Sometimes it’s just not feasible to have the sub (or child) pages listed within your sidebar in WordPress, especially if you have a lot of child pages. However, instead of needing to manually add each link to its parent page, you can quickly do it with a bit of PHP goodness. Using the following code within your page.php file will add a list of all the sub pages to the currently viewed parent page.
<?php
$children = wp_list_pages(’title_li=&child_of=’.$post->ID.’&echo=0′);
if ($children) { ?>
<h4>Additional Resources</h4>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
Please note that the above code must be used within the WordPress loop in order to work. (I personally prefer to put it right after <?php the_content(); ?> so it will display the list of sub pages after the page content.)
To remove the sub pages from showing under the parent pages in the sidebar, add ‘depth=1′ in addition to any other variables in the wp_list_pages() code within your sidebar. Example: <?php wp_list_pages(’title_li=&depth=1′); ?>



Now that was some useful information. I am a php noob so any code hacks or tricks are definitely useful information.
# December 11th, 2007
Very useful; I’ll try it on one of my blogs. Thanks.
# December 16th, 2007
This is the one area were WordPress lacks for CMS capability and this lil hack will help hopefully!!
# December 16th, 2007
Hey Teli, two questions on coding edits in WordPress. First, I don’t know how to actually get into any of the files to edit them so if you could tell me how that’s done that would help me address these items.
1. How do I add my picture to the header or one of the side columns?
2. How do I install a simple post tagging feature that becomes part of the template at the bottom of each post so I can custom tags to each post.
Thanks for your help.
# December 30th, 2007
Whoops, I don’t think I clicked the follow up with comments with e-mail check box so please shout back at me that way too.
Thanks…..martin
# December 30th, 2007
Whilst that’s a nice Wordpress hack, I’ve been nervous of hacking my own blog too much, due to the issues of upgrading later. Do you have any advice on how to keep track of hacks like this and how to incorporate them into future wordpress upgrades?
# January 2nd, 2008
I do prefer some kind of plugin for this too. Since I’m a noob and it looks like you know much more about it :), is it possible for you to make such a plugin ?
Dave
# January 20th, 2008
Thanks for the code. I am with a PP, This noob appreciates the help and insight.
# February 29th, 2008
Thanks for the tips and I had it on my sidebar. Just that I fail to get the subpages indented….:(
# March 20th, 2008