0

I created a code for querying child pages when we're on a parent page and also display brother pages if we are on a child page, and works amazing... now my problem is, I cannot find a parameter like post_per_page that allow me to limit the number of page displaying, so far I need to display 5, but if a 6 is added the style breaks... so at the end of the day I just want to limit the number of view to X number, lets say 5.

Take a look at the code

 <nav>
   <ul>
     <?php
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      $subpages = ($post->post_parent) ? wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0') : wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0') ; 
          if ($children) { ?>
             <li><?php echo $children; ?></li>
          <?php } else { ?>
             <?php echo $subpages; ?>
     <?php } ?>
   </ul>
 </nav>

Thanks in advance.

UPDATE**

I found this solution after a while

 <?php $this_page_id=$wp_query->post->ID; ?>
   <?php query_posts(array('orderby' => 'menu_order', 'order' => 'ASC', 'posts_per_page' => 2, 'post_parent' => $this_page_id, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>

        <li><?php the_title(); ?></li>

   <?php } ?>
   <?php wp_reset_query() ?>

I'm able to use the post_per_page function and works like charm!

0

Maybe array_slice($subpages, 0,5) to cut the array after 5 entries?

  • I tried but it seems not to work =( – andresmijares Nov 17 '11 at 20:23
  • Sorry, did you tried the depth argument ? – Simon Nov 17 '11 at 20:27
  • No, depth is for ... depth, not number. There were supposed to be a number parameters, but it's not working : core.trac.wordpress.org/ticket/10745 – Simon Nov 17 '11 at 20:40
  • yeah that number parameter is not working at all, weird stuff – andresmijares Nov 17 '11 at 20:57
  • So the answer would be to find a way to cut the variable after 5 hits. I'm working in somehow the same problem on another question, so if something comes out, i'll let your know. But maybe you could do a loop five times with a foreach...while (i <5) and a break ; and each time taking permalink and title of the current object. – Simon Nov 17 '11 at 22:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.