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. >
Some of the answers on this page have slightly outdated info. Namely, exclude
no longer seems to be needed when using child_of
.
Here's my solution:
// if this is a child page of another page,
// get the parent so we can show only the siblings
if ($post->post_parent) $parent = $post->post_parent;
// otherwise use the current post ID, which will show child pages instead
else $parent = $post->ID;
// wp_list_pages only outputs - elements, don't for get to add a
echo '
';