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.

How to set the menu active state for a custom posttype and category, given a custom taxonomy term?

I have a custom taxonomy: region, a custom posttype: business, and use the categories taxonomy. My custom primary menu consists of the region terms.

When I select a region, the corresponding menu item is highlighted OK. The region page shows a listing of relevant categories. Now, when I select a category on this page the corresponding menu item is not highlighted. In turn, the category page shows a listing of businesses. Also, when I click on a business, the corresponding menu-item is not highlighted.

So, how to set the menu active state on a category page and on a business post, given a custom taxonomy term? I do have a session variable region available on these pages.

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

When you create a custom menu item for the custom post type archive you have to include the entire url and not just '/your-custom-post-type-name'. If you use the entire url the wordpress url rewrite function will check it against all the other menu items as well as against all your pages and so on. What you end up with in the menu parent is something like 'current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor'.

share|improve this answer
    
Thanks. That definitively is more flexible! However I noticed that not in all cases the current-menu-ancestor, current-menu-parent, current_page_parent and current_page_ancestor get set. This is e.g. the case when showing a (custom) post belong to a category listed as a child in a custom menu. Nevertheless, the solution you pointed out is workable in most cases. –  Henk Jan Apr 12 '11 at 6:33
add comment

You probably can do this via CSS. As the body has classes lined up depending on the page that is displayed and the menu entries have classes and ids on their own, you can probably hardcode the highlight into custom CSS.

If the highlighting is done with markup instead of CSS then this is not possible. But I think that is not the case.

So inspect (e.g. with Firebug) the body tag on those pages and check for the ids of the menu items. Next to that you can check how the highlighting is done with Firebug.

The rest should be copy and paste.

share|improve this answer
    
Thanks for the answer. I think it will work for me - I will check it out tonight. –  Henk Jan Dec 17 '10 at 14:45
    
Worked out allright. Thanks. (only drawback: this solution is not flexible - but hey, I am happy with your solution) –  Henk Jan Dec 17 '10 at 21:49
    
@Henk: Yes, it's sort of hardcoded, but you could genererate the CSS based on the page. So it would become a bit more flexible. –  hakre Dec 17 '10 at 23:58
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.