I'm trying to build a list of the first subpage out of 10 pages.

So my page structure is this:

  • Page A
    • Page A1
    • Page A2
  • Page B
    • Page B1
  • Page C
    • Page C1
    • Page C2
    • Page C3

And I'd like to display this list in my template:

  • Page A1
  • Page B1
  • Page C1

I'm pretty close, but I'm stuck on a bug in WP_List_pages that causes the number parameter to not work (http://core.trac.wordpress.org/ticket/10745). This means all the subpages are always displayed, whereas I only want to display the first subpage. This is the code I'm using:

        'post_type'     =>'page',
        'showposts'     =>10
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) { ?>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            $children = wp_list_pages('title_li=&child_of='.$id.'&echo=0');
            $pieces = explode('"', $children);
        <?php endwhile; ?>
        <?php } //if ($my_query)
        wp_reset_query();  // Restore global post data stomped by the_post(). ?>

I'm thinking I'll need a for loop to only display the first post, but my php knowledge is lacking so I'm kind of stuck. Anybody in for a quick answer?

1 Answer 1


You can hook into the edit_posts_per_page filter that fires in WP_List_pages right before the pagination is determined.

add_action( 'edit_posts_per_page, 'limit_list_pages' );

function limit_list_pages() {
        $post_type ='post';
        $edit_per_page='edit_' . $post_type . '_per_page';
        $per_page=(int)get_user_option( $edit_per_page );
        if ( empty( $per_page ) || $per_page < 1 )
            $per_page=10; //<--- Change this to your new per page number

        return $per_page;

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.