I have the following structure of pages, and I need to have that same structure displayed on those pages who have child pages:
- Childpage
- - Grandchildpage
- - Other Grandchildpage
- Other Childpage
The following code is used to display the structure on page.php:
<ul class="sidemenu-list">
<?php
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=1");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=1");
if ($children) { ?>
<ul>
<?php echo $children; ?>
</ul>
<?php } ?>
</ul>
This works when on the parent page. But when I'm on one of the childpages or grandchild pages, this doesn't work anymore.
Following above structure example, when I'm on 'Childpage' I only get the following:
- Childpage
- Other Childpage
And when I'm on 'Grandchildpage' I only get:
- - Grandchildpage
- - Other Grandchildpage
What is the correct way to display the page hierarchy even when the page is a child or grandchild?