CSS Style center

CSS Styles, CSS tips

Portfolio

Display Child Pages title & content on Parent Page

I am developing a custom theme for my client, and there was a need to show the title and the content of the child pages under the specific page within the website.

I’ve been looking for a solution for a few days already and every solution iv’e found did the same thing, it posted the titles of the child pages but the content under these titles was the content of the current page i have been on.

Eventaully i have made some adjustments on a code i have found on a wordpress support forums and it worked perfectly.

Here is the code:

<?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;
?>
<h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
<p><?php echo $content ?></p>
<?php
}
?>

This way the page that you are on will show in a post type the child pages of that page.

5 Responses to Display Child Pages title & content on Parent Page

Sea says: September 15, 2010 at 3:21 am

I used this code and I ended up losing all the return carriages in the content. I can’t seem to figure out where it is all falling to pieces. The wordpress entries are normal, but when they post on the page… they become one giant paragraph.

Nick says: May 18, 2011 at 9:15 pm

I tried this as well and I am also not getting carriage returns and I have changed line 9 to ?php echo $page->post_content ?>

stephen says: January 2, 2012 at 3:20 pm

FYI, you are missing the filter before outputting the content.

Try adding the following:

$content = apply_filters( ‘the_content’, $content );

before echoing the content

Hope this helps…

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>