Home » Wordpress

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

19 November 2008 95 views 2 Comments

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 } ?>

Popularity: 7%

Related posts:

  1. New Wordpress Plugin – Author Introduction
  2. Wordpress Plugin: Quick Adsense 1.0
  3. Wordpress: Optimizing 404 Page Not Found page
  4. Wordpress: Create custom archive page
  5. Left or Right Align your image, adsense code or other advertisement in wordpress
Share/Bookmark
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

2 Comments »

  • Gui said:

    Perfect thank you so much!

  • John said:

    Excellent, now how I can change how the pages are listed in the sidebar

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

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

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.