• I’ve got he following code working on a page, displaying all the children pages. However some pages have like 50 pages. So I’d like to restrict it to the last 10.

    <ul>
    <?php
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_modified&sort_order=desc');
    	$count = 0;
    	foreach($pages as $page)
    	{ ?>
    		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a><br />
    	<?php
    	}
    ?>
    </ul>

    However when I add &number=10 to the code below I get nil results.

    <ul>
    <?php
    	$pages = get_pages('child_of='.$post->ID.'&sort_column=post_modified&sort_order=desc&number=5');
    	$count = 0;
    	foreach($pages as $page)
    	{ ?>
    		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a><br />
    	<?php
    	}
    ?>
    </ul>

    Anyone got any ideas ?

    Cheers

    Benjamin

Viewing 5 replies - 1 through 5 (of 5 total)
  • <ul>
    <?php
    $count = 0;
    $pages = get_pages('child_of='.$post->ID.'&sort_column=post_modified&sort_order=desc');
      foreach($pages as $page) {
        $count++;
        if ( $count < 11 ) {  // only process 10 ?>
          <a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a><br />
        <?php
        }
      }
    ?>
    </ul>
    Thread Starter chefben

    (@chefben)

    Michael,

    Thanks for this.

    Would you use similar code to get 10 Random ? Also struggling with this.

    Cheers

    Benjamin

    I too ran into the same issue with &number= not returning any results, using WP 2.9.2. So it doesn’t work at all? Or just doesn’t work with “child_of”?

    Either way, maybe someone should edit “number” in the get_pages parameters…

    http://codex.wordpress.org/Function_Reference/get_pages#Parameters

    I’m using the following code to display “child”. i was wondering is there a way not to display “grandchild”? I didn’t see any option for it.

    thanks

    <?php
    $count = 0;
    $pages = get_pages('child_of=1119&sort_column=post_date&sort_order=desc');
      foreach($pages as $page) {
        $count++;
        if ( $count < 50) {  // only process 10 ?>
         <div class="main_post_listing">  <a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a><br /></div>
        <?php
        }
      }
    ?>

    i got it working

    <?php wp_list_pages(‘title_li=&depth=1&child_of=1119&sort_column=post_date&sort_order=desc&number=10’); ?>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘get_pages and limiting number of child pages displayed’ is closed to new replies.