WordPress and child page listing

Sometimes I want a listing of the child pages to be embedded in the text of a page. This could be done manually but then maintenance of the site is a nightmare (unless it is a really static site!)

So adding the following code into the relevant page template for the WordPress site works a treat.

[php]
<?php
$children = wp_list_pages(‘title_li=&child_of=’.$post->ID.’&echo=0′);
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
[/php]

While it is not a rule, this related page listing is probably going to appear underneath any of the page text content, so look for the following in the page template and place the child page code below this line.

[php]
<?php the_content(); ?>
[/php]

One reply

Leave a Reply

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