Home » Wordpress

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

19 November 2008 2,403 views Popularity: 5% Share/Bookmark

email

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

Related posts:

  1. WordPress: Optimizing 404 Page Not Found page
  2. WordPress: Create custom archive page
  3. Left or Right Align your image, adsense code or other advertisement in wordpress
  4. WordPress: Archive link not working
  5. WordPress Plugin: Quick Adsense 1.0
  6. WordPress MU: Admin login problem
  7. Javascript: Show/Hide HTML elements
  8. Magento: Get current and parent category
  9. Twitter, Facebook, WordPress getting together
  10. jQuery: Grey out background and preview image as popup
  • http://www.ahoodie.com Gui

    Perfect thank you so much!

  • http://www.freeseoinformationblog.com John

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

  • http://wp-popular.com/popular-word-press-websites/how-to-show-child-page-sub-page-list-in-parent-page-in-wordpress-mukesh-chapagains-blog/ wp-popular.com » Blog Archive » How to show child page (sub page) list in parent page in wordpress? | Mukesh Chapagain’s Blog

    [...] here to read the rest: How to show child page (sub page) list in parent page in wordpress? | Mukesh Chapagain’s Blog Tags: layout, [...]