Jump to content
Sign in to follow this  
Mike

Add parent to secondary nav

Recommended Posts

Mike

Hi, I've got the drop down menus disabled and instead using child pages for secondary nav. What's the best way to add the parent to the beginning of the menu? E.g.: Parent 1 | Parent 2 | Parent 3 [primary nav] Parent 2 | Child 1 | Child 2 | Child 3 [secondary nav] I found this thread from last year but it doesn't really give a good option. Do I have to create & keep updating a custom menu for every set of children? Where abouts is the code that generates the secondary nav? I had a quick look but couldn't find it.

Share this post


Link to post
Share on other sites
Rob
Okay, perhaps there's a little misunderstanding of what Secondary Nav does and where/how it's applied. Your Child Pages will appear dynamically, I believe in date order (most recent first) in the parent page. As someone would/should know where they've arrived (or you can tell them with automated page titles) then anything under the secondary nav should be self-evident. You might consider doing something with CSS to color the secondary nav background and have the same color apply as a background in active state in the primary nav menu. Thus, let's say your visitor is on Parent 2, the background color there will be perhaps baby-blue as will the secondary nav, while the rest of the parent options have a deep blue background. I don't think the order of the secondary nav can be changed, except by setting the date of your pages.

Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites
Mike
Thanks for your reply. I understand what you're saying but for various reasons I just want the parent repeated. The top level pages are acting like starting points to different sections so I'd like them to be in the flow of the secondary nav. The following code does exactly what I need: [code]post_parent){ $ancestors = array_reverse(get_post_ancestors($post->ID)); return $ancestors[0]; } return $post->ID; }} ?>
    '','include'=>get_post_top_ancestor_id()) ); ?> '','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
[/code] How would I go about hooking that in to pagelines_after_nav? p.s. the order of the secondary nav is set by the order attribute of the child pages in the same way that the order of the top level pages is done

Share this post


Link to post
Share on other sites
Mike
Never mind, got it working - had never used hooks before but surprisingly easy! Here it is if anyone's interested. [code]add_action('pagelines_after_nav', 'add_sec_nav_w_parent'); function add_sec_nav_w_parent(){ if(!function_exists('get_post_top_ancestor_id')){ function get_post_top_ancestor_id(){ global $post; if($post->post_parent){ $ancestors = array_reverse(get_post_ancestors($post->ID)); return $ancestors[0]; } return $post->ID; }} ?>
    '','include'=>get_post_top_ancestor_id()) ); ?> '','depth'=>1,'child_of'=>get_post_top_ancestor_id()) ); ?>
[/code]

Share this post


Link to post
Share on other sites
Mike
Better version in case anyone comes across this in the future: [code]add_action('pagelines_after_nav', 'add_sec_nav_w_parent'); function add_sec_nav_w_parent(){ global $post; ?>
    post_parent) { // If post has parent, list that parent and all its children wp_list_pages( array('title_li'=>'','include'=>$post->post_parent) ); wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->post_parent) ); } else if(get_pages('child_of='.$post->ID)) { // If post is a parent, list itself and all children wp_list_pages( array('title_li'=>'','include'=>$post->ID) ); wp_list_pages( array('title_li'=>'','depth'=>1,'child_of'=>$post->ID) ); } ?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×