Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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...

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.

share|improve this answer
    
Awesome, perfect answer. Thank you! –  aendrew May 4 '11 at 10:19
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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