Display All Subpages in Sidebar
category: Snippets | Tags: development, sidebar, subpages.
The cleanest way to display a list of subpages in your theme is the following.
First you have to add a piece of code in the functions.php file of your theme
<?php // paste this in functions.php
function wpe_highest_ancestor(){
global $post;
$page_ancestors = end($post->ancestors);
if(!empty($page_ancestors)){
$child_of = $page_ancestors;
}else{
$child_of = $post->ID;
}
return $child_of;
}
?>
Then you can just call this function in combination with the wp_list_pages tag
<ul class="subpages">
<?php wp_list_pages('child_of=' . wpe_highest_ancestor()); ?>
</ul>
Leave a Reply
Read more articles...
BlogBuzzer
Blog Buzzer is a FREE easy to use tool that helps authors of blogs get their work noticed. Most blog entries are found by ot… read more
Geeks Are In
GeeksAre.In is a blog/magazine where i share with the world and my friends anything geeky and interesting i find online along with my thoughts.
techWALL
The best tech and technology news, developments and trends. Coverage includes hardware, software, internet and many more of the world of tech!
R.fm – The Finest Blend of Club Culture
R.fm is a gallery website by Gustav Bagge. The dark color scheme looks very stylish and surely adds something more to the overall picture. It’s a multicolumn theme that varies from two to four columns (2 for the post page, 4 for the home page).


Share on Facebook
Share on twitter
Subscribe to our RSS
