Buzzslot, Web trends, internet strategy, design, blogging

Display All Subpages in Sidebar

category: Snippets | Tags: , , .

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