views:

379

answers:

2

I am trying to create a list of sibling pages (not posts) in WordPress to populate a page's sidebar. The code I've written successfully returns a page's parent's title.

<?php
$parent_title = get_the_title($post->post_parent);
echo $parent_title; ?>

As I understand it, you need a page's id (rather than title) to retrieve a page's siblings (via wp_list_pages). How can I get the page's parent's id?

Alternate approaches are welcome. The goal is to list a page's siblings, not necessarily just retrieving the parent's id.

+1  A: 

$post->post_parent is giving you the parent ID, $post->ID will give you the current page ID. So, the following will list a page's siblings:

wp_list_pages(array(
    'child_of' => $post->post_parent,
    'exclude' => $post->ID
))
Richard M
A: 
<?php if($post->post_parent): ?>
<?php $children = wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'); ?>
<?php else: ?>
<?php $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'); ?>
<?php endif; ?>
<?php if ($children) { ?>
<ul class="subpage-list">
<?php echo $children; ?>
</ul>
<?php } ?>

Don't use the exclude parameter, just target that .current_page_item to differentiate.

Allan