I've got a site with the following structure:
About
- Page 1
- Page 2
- Page 3
- Page 3.1
- Page 3.2
So Page 1, Page 2,... are subpages of the About page. I would like to have a sidebar that lists the pages, but only shows the subpages when needed. So when I'm on Page 1, I need to see:
- Page 1
- Page 2
- Page 3
And when I'm on Page 3 I need to see:
- Page 1
- Page 2
- Page 3
- Page 3.1
- Page 3.2
Also, when I'm on Page 3.1 or 3.2 I'd like to see the same thing. I've got following code so far:
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&depth=1");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
But when I'm on Page 3 now, the subpages don't get listed. I've tried adapting the code in various ways, but either the subpages don't get listed, or the parent pages or siblings don't display... Anyone has a suggestion or a solution about this one? Thanks.