2

TwentyTen adds some classes to custom menus, for instance:

#access #menu-item-262.current-menu-item, #access #menu-item-262.current-menu-ancestor

All the top-level links in my primary navigation have the class .current-menu-ancestor when the user is on a child page -- except when I'm viewing content in the custom post type I've built.

How do I set the current page in navigation when viewing a custom post type?

Thanks...

2 Answers 2

2

The classes are not added by the Twenty Ten theme, but by the common custom navigation menu code, in _wp_menu_item_classes_by_context(), which is called from wp_nav_menu().

If you want to add extra classes you can do that by either hooking into wp_nav_menu_objects, called once with the whole menu tree, or into nav_menu_css_class, called when rendering each individual item.

0
0

I figured this out as I was typing out the answer.

If you have the line: <body <?php body_class(); ?>> in your header.php for your body tag, custom post templates will each have their own body class. Because in my case all content in that custom post type is under one section of my navigation bar, I was able to simply add the body class before the declaration, i.e., .single-film #menu-item-262 where "film" is the name of my custom post type.

That said, this solution won't work for sites where custom post types reside under different parts of the navigation. Is there a better way to go about this than I did?

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.