How to adding list with parent & children in sidebar

Hi there!

I have just added a subpage to a page on my blog for the first time, and would love to display a list in the sidebar on the parent that displays the parent itself, and all children. On the childpages, this same list (parent+children) should be visible.

Looking through the codex, I found the following:

//if the post has a parent
//collect ancestor pages
$relations = get_post_ancestors($post->ID);
//get child pages
$result = $wpdb->get_results( “SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type=‘page’” );
if ($result){
foreach($result as $pageID){
array_push($relations, $pageID->ID);
//add current post to pages
array_push($relations, $post->ID);
//get comma delimited list of children and parents and self
$relations_string = implode(",",$relations);
//use include to list only the collected pages.
$sidelinks = wp_list_pages(“title_li=&echo=0&include=”.$relations_string);
// display only main level and children
$sidelinks = wp_list_pages(“title_li=&echo=0&depth=1&child_of=”.$post->ID);

if ($sidelinks) { ?>

<?php the_title(); ?>

    <?php //links in
  • tags echo $sidelinks; ?>
<?php } ?>[/php]

This works perfect on a child page, displaying child and parent in a neat linkable list. But on the parent page it only displays the child. How can I also add the parent there?

I am also curious how to delete the ‘title’ this list has. Now it just adds the parents name in plain text…

Thank you in advance for your help!

Sponsor our Newsletter | Privacy Policy | Terms of Service