WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using the following code to display child page content on it's parent page. The code is working great, but it currently only shows the latest two child page posts, is there any way to display all of them and then add pagination to navigate through them?

    $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
    $count = 0;
    foreach($pages as $page) {
        $content = $page->post_content;
        if($count >= 2)
        $content = apply_filters('the_content', $content);
        echo "<h2>".$page->post_title."</h2>";
        echo "<p>".$content."</p>";


share|improve this question
up vote 1 down vote accepted

After some searching I was able to find this post: http://wordpress.org/support/topic/add-pagination-to-list-of-child-pages

My final code looks like this:

    $ids = array();
    $pages = get_pages("child_of=".$post->ID);
    if ($pages) {
        foreach ($pages as $page) {
            $ids[] = $page->ID;
    $paged = (get_query_var("paged")) ? get_query_var("paged") : 1;
    $args = array(
        "paged" => $paged,
        "post__in" => $ids,
        "posts_per_page" => 2,
        "post_type" => "page"
    if (have_posts()) : while (have_posts()) : the_post(); 
    <h2><?php the_title(); ?></h2>
    <p><?php the_content(); ?></p>
<?php endwhile; else: ?>
    <h2>Oh No!!</h2>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<?php echo get_next_posts_link(); ?>
<?php echo get_previous_posts_link(); ?>
<?php wp_reset_query(); ?>

I really like this code because it pulls the content using a loop, making it easier to pull the things you want from the page (as well as creating a custom query)...I edited a few lines from the link I found and tried to simplify it as much as possible.

I hope this helps someone else out there, worked like a champ for me!

Note: I wanted to display just the child pages and no grand child pages, so if you'd also like to do that add "parent=".$post->ID to line 3 in the code above. *The line will look like: $pages = get_pages("parent=".$post->ID."&child_of=".$post->ID);


share|improve this answer

Your Answer


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.