Web design

Show Siblings or Children of a Wordpress Page

A useful code snippet I thought I’d share

<div id="subpages">
<h3>Related Pages</h3>
<?php
// If CHILD_OF is not NULL, then this page has a parent
// Therefore, list siblings i.e. subpages of this page's parent
if($post->post_parent){
    wp_list_pages('title_li=&include='.$post->post_parent);
    wp_list_pages('title_li=&child_of='.$post->post_parent);
    }
// If CHILD_OF is zero, this is a top level page, so list subpages only.
else{
    wp_list_pages('title_li=&include='.$post->ID);
    wp_list_pages('title_li=&child_of='.$post->ID);
    }
?>
</div>

4 Comments

  1. Posted November 18, 2009 at 10:01 pm | Permalink

    Thanks for this! Exactly what I needed. Kudos!

  2. Posted February 15, 2010 at 1:04 pm | Permalink

    thanks so much for sharing this – really handy! (should have seen this last week when i was editing a theme)

  3. Posted March 11, 2010 at 7:37 pm | Permalink

    Thanks for this snippet! I had been using a piece that was more complicated to do the same thing, but this is even better.

  4. Nick
    Posted June 17, 2010 at 10:57 pm | Permalink

    Brilliant! Huge help! I will use this on pretty much all of my client’s WordPress sites.

Post a Comment

I welcome your thoughts and comments. Please note that comments are moderated, therefore your comment will not appear immediately. Comments may be edited or deleted at my discretion. For more information please consult my comment policy.

Your email is never published nor shared. Required fields are marked *

*
*

Comment moderation is enabled. Your comment may take some time to appear.