I’ve been playing around with WordPress’ menu functionality (wp_nav_menu and wp_list_pages) to build a menu for my site. It’s coming along, but I’m still having some trouble getting the behaviour I’d like.
What I’d like is something like the sidebar menu on this website (not WP): http://www.fairfood.org/facts/sustainability-agenda/
When you click on a subpage that has children, the menu displays those children:
http://www.fairfood.org/facts/production-chains/
I currently have this code:
<?php // sidebar menu
if ($post->post_parent) {
$ancestors=get_post_ancestors($post->ID);
$root=count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
$children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0");
if ($children) { ?>
<ul id="subnav">
<?php echo $children; ?>
</ul>
<?php } ?>
This works, but this shows the children that all the subpages have, not just the children of the current page. An example of what I mean: http://test.fairfood.org/facts/
Any have any idea to make this work?
If you dont mind using a plugin I can tell you how I have gotten this to work in the past.