How to show child page (sub page) list in parent page in wordpress?

Suppose, you have many sub pages (child pages) of a single parent page. You want to show the list of all the child pages in the parent page.

You can show the list of pages and sub pages in the sidebar of your wordpress theme with the addition of in-built sidebar widget called ‘Pages’. This will show all your pages and sub pages nested inside parent pages.

I will be showing, how you can show the list of the sub pages in the parent page body (not in the sidebar but in the main body of the page).

Suppose, you have created a page called ‘Sports’. Under ‘Sports’, you have two sub pages called ‘Cricket’ and ‘Football’.

The process of creating a sub page/child page is as under:

1) First you create a page called Sports. You choose page parent as ‘Main Page’.

2) Then you create another page called ‘Cricket’. You choose page parent as ‘Sports’. Now, page cricket becomes the sub page of the page Sports.

Below is the code to show the list of sub pages in the parent page body. You have to put this code inside the the_post() section of the page.php template of your WordPress theme after the_content().

For WordPress 2.0.1 or older:


<ul>
<?php
global $id;
wp_list_pages("title_li=&child_of=$id&show_date=modified
&date_format=$date_format"); ?>
</ul>

For WordPress 2.0.1 or newer:


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

Thanks.