Question

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!

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à wordpress.stackexchange
scroll top