Reputation: 269
I currently have a navigation bar displaying all the children of that specific page using the following snippet
<div id="sub_nav_del">
<h4>Take a seat</h4>
<?php
$pages = get_pages('child_of='.$post->ID.'&sort_column=menu_order');
$count = 0;
foreach($pages as $page)
{ ?>
<ul>
<li>
<h5 class="del">
<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>
</h5>
</li>
</ul>
<?php
}
?>
</div>
However I would like the navigation to still be displayed if I am on one of the child pages.
Upvotes: 0
Views: 515
Reputation: 2847
You could determine the post-ID for your get_pages
-call by asking for a page's parent. If it has no parent, the page's ID will be used.
$subnav_parent = ($post->post_parent) ? $post->post_parent : $post->ID;
$pages = get_pages('child_of=' . $subnav_parent . '&sort_column=menu_order');
However I can tell you, it won't work for third level pages, but for second level it will be all fine.
Upvotes: 1