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.

OK so i have a main menu and a sub-menu

How can i make a menu item active when viewing a single post.

The sub-menu uses taxonomies so i know i need to make the taxonomy active when one of the posts has the taxonomy in use

share|improve this question
    
What does the main menu show? –  Lea Cohen May 9 '11 at 5:21
    
shows home movies music sub-menu for movies is action adventure drama etc and music is rock hiphop country metal etc –  xLRDxREVENGEx May 9 '11 at 5:41
    
but i need the sub menu highlited not the main. i already have code in place when viewing the sub-menu items but need to code when a post is active –  xLRDxREVENGEx May 9 '11 at 5:42
    
So can anyone else help me –  xLRDxREVENGEx May 10 '11 at 0:54
    
Could you show the code with which you create the sub menu that shows the the taxonomies? And another thing - if a post has more than one tag, you want all the tags that it has to be highlighted? –  Lea Cohen May 10 '11 at 17:01

4 Answers 4

I did something similar with highlighting current category in navbar, you can see my answer here. The hook of course won't work for you, I think a better hook would be 'nav_menu_css_class'

share|improve this answer
    
Sorry i havent been able to try this yet. I have had some other problems happen with my site and they need priority. When i get a change ill post back. –  xLRDxREVENGEx May 13 '11 at 1:20
    
I dont think this is going to work as there are some things that are for categories and i tried changing them out and that did not work –  xLRDxREVENGEx May 17 '11 at 22:44
    
I could not get it to work but i did use this on another project. So ill mark as answered –  xLRDxREVENGEx May 21 '11 at 18:23
    
@xLRDxREVENGEx - thank you, that's very kind of you. Although it might be misleading to mark as answered a question that you still need an answer for... Maybe just up upvote (if you want)? Or nothing? –  Lea Cohen May 21 '11 at 21:20
up vote 1 down vote accepted

So i ended up doing some jquery and lots of it. The downside is that i have to add the code each time i create a new menu. I am looking into re-creating this but do not want to bother with it right now. This is the link to the solution. It is very very temporary so if you wish to use it go ahead but there are better ways. You may be able to hook into the wp_nav_menu classes and add a active class to the current active item and then use some jquery to finish it off.

share|improve this answer

have a read of this codex: http://codex.wordpress.org/Dynamic_Menu_Highlighting

share|improve this answer
    
Have read it but will not do what i want. The default core setup highlights categories not tags –  xLRDxREVENGEx Jun 13 '11 at 20:27

You can check the slug and and the current taxonomy against one another.

For example if you were outputting a menu using get_terms($taxonomy) you could use an if statement to check whether the current page's taxonomy is the same as the slug menu item and give it an active class.

            <?
                $taxonomy = 'disciplines';
                $tax_terms = get_terms($taxonomy);
                $current_taxonomy = get_query_var($wp_query->query_vars['taxonomy']);
                foreach ($tax_terms as $tax_term) {

                    if ($current_taxonomy == $tax_term->slug) {
                        $active = 'active';
                    }

                    echo '<li class="filter ' . $active . ' clearfix"><a href="/disciplines/' . $tax_term->slug . '"><i class="fa fa-circle-o"></i><i class="fa fa-circle"></i> ' . $tax_term->name . '</a></li>';

                    $active = "";
                }
            ?>

Where discipline is your custom taxonomy.

share|improve this answer

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.