Hi Everyone! It’s been a while since my last tutorial, so here’s a quick bit of code I want to share, since I’ve found myself using it a lot.
For sites that have a large number of pages setup hierarchically, adding them all to the drop-down menu doesn’t make sense. Same with just adding the pages widget to the sidebar, since anything more than a few pages quickly becomes overwhelming. The best happy-medium I’ve found so far is to display pages that have the same parent as the current page in a list in the sidebar.
function pages_sidebar() { if(is_page()) { ?> <!-- Show only on single pages -->
<li id="pages_widget" class="widget">
<?php
global $post; // Get the post information for the current page
if($post->post_parent) // Check to see what the page's parent is
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1"); else // List child pages of page's parent
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1"); // List child pages of current page
if ($children) { ?>
<h3>Related Pages</h3> <!-- Widget title -->
<ul>
<?php echo $children; ?> <!-- Echo queried pages -->
</ul>
<?php } ?>
</li>
<?php } }Once you add that to your custom_functions.php file, you can then hook it in to your desired position. I use
add_action('thesis_hook_before_sidebar_1', 'pages_sidebar');But any hook will do. From there, you can use CSS to style the widget however you like.




