Daily Archives: 2010-03-19

How to show WordPress page hierarchies

Got a request for help from some the Eyebeam list. 1 The folks organizing the Urban Wilderness Action Center for the international Electrosmog festival 2 wanted some usability help.  Navigating between subpages of their projects was too confusing.

If you like the way the sub pages are listed out on, say, the Berlin Micro-Turf Expedition – here you go.

<?php
// Does this even have a parent?
if($post->post_parent) {
$parent_title = get_the_title($post->post_parent);
?>
<a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a>:
<?php } ?>
<?php
//ok let's find our sibling pages, but we don't need to list the current page
if ( ($post->post_parent) && (get_post($post->post_parent)->post_parent) )
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&exclude=".$post->ID."&echo=0");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
if ($children) { ?>
<ul style="display:inline">
<?php echo $children; ?>
</ul>
<?php } ?>
  1. The Eyebeam folks are doing a cool skillshare on how “Tools and Models for Online Collaboration”  (back)
  2. It starts March 20th!  It’s completely free!  Go!   (back)