Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

        <?php
        $args=array(
        'post_type'     =>'page',
        'showposts'     =>10
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) { ?>
        <ul>
        <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <?php 
            $children = wp_list_pages('title_li=&child_of='.$id.'&echo=0');
            $pieces = explode('"', $children);
<-- STUFF GOES HERE? -->
            ?>
        <?php endwhile; ?>
        </ul>
        <?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?

share|improve this question

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;
    }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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