Hello,
I have a menu that's 3 levels deep. The third level menu item, when clicked, shows a blog view of posts from a custom post type. Wordpress generates current menu classes up to this point but when you click on one of the item titles on the third level blog view page all my current menu classes disappear, therefore my sub navigation disappears.
What I need is the current menu classes to stay active when visiting a single page.
Here's the link to the third level blog view page:
[[LINK href="http://demo.christinesutherland.com/television-series-category/the-magic-of-massage"]]http://demo.christinesutherland.com/television-series-category/the-magic-of-massage[[/LINK]]
Denis
Daniele Raimondi answers:
If I understand correctly your problem I think you can found the definitive solution [[LINK href="http://wordpress.stackexchange.com/questions/3014/highlighting-wp-nav-menu-ancestor-class-w-o-children-in-nav-structure"]]here[[/LINK]]
You can also use the menu item descrition field to get this trick working (if you're already using the title field for other pourposes). Just change the <strong>attr_title</strong> with <strong>description</strong>:
function current_type_nav_class($classes, $item) {
$post_type = get_post_type();
//krumo($post_type,$item);
if ($item->description != '' && $item->description == $post_type) {
array_push($classes, 'current-menu-item');
};
return $classes;
}
add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2 );
Denis Leblanc comments:
Thanks Daniele,
This sounds like a legitimate fix. I'll give it a go.
What's with the commented line: //krumo($post_type,$item);
Christianto answers:
Is this main menu or widget menu? little confuse since the menu on sidebar...Do you have setting to increasing menu level deep more than 3 level?
Also Have you tried to create level 4 menu pointing to Episode One, Episode Two, Episode Three?
Denis Leblanc comments:
It's a custom menu built from the >Appearance >Menus tab. See the attached image.