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?
<?php
$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)
break;
$count++;
$content = apply_filters('the_content', $content);
echo "<h2>".$page->post_title."</h2>";
echo "<p>".$content."</p>";
}
?>
Thanks,
Josh
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:
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
toline 3
in the code above. *The line will look like:$pages = get_pages("parent=".$post->ID."&child_of=".$post->ID);
Thanks,
Josh