Limit the number of child page displaying

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

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!

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!

Share Improve this question edited Dec 6, 2011 at 2:32 andresmijares asked Nov 17, 2011 at 18:36 andresmijaresandresmijares 1,0483 gold badges13 silver badges27 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742326154a4422791.html

相关推荐

  • Limit the number of child page displaying

    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

    14小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信