highlight parent and current child category when viewing single post
-
Hi, I’m having a problem when trying to dynamically highlight a parent menu item when a child sub category item is selected. Also, if a post is selected under the subcategory, I’d like the top level parent menu item to stay highlighted.
The template I’m using has the top level parent item a non-link and not a category, and the submenu items are the categories.
Here’s that code from my header:
<li><a>Work</a> <ul> <?php wp_list_categories("exclude=$blog_ID&title_li="); ?> </ul> </li>
So in this scenario, when you roll over “Work” in the menu, work is not clickable, but you get a drop down submenu with clickable category links, like “interactive,” “email,” “print,” etc. That’s just how the template I’m using is set up.
I know how to make single Home, About and Contact pages dynamically highlight, here’s the php and css I’m using for those:
code:
<li<?php if (is_page('About')) { echo " id=\"current\""; }?>> <a href="<?php bloginfo('url') ?>/about">About</a> </li>
css:
#current a {font-weight:bold;color:#e2007d;}
Here’s my test site:
https://www.newsite.blairshapiro.com
Again, it should be that only the parent menu item, “Work,” stays highlighted when one of the child submenu items OR one of the posts belonging to the particular submenu child is selected. I hope that’s clear.
I think it has something to do with the is_category, in_category and if/else statements as well as the css, but I just can’t put together the right combination to make it work.
I’m sort of a newb, can anyone show me an example of the code and css to use to achieve this?
Any help would be appreciated.
Thanks!
- The topic ‘highlight parent and current child category when viewing single post’ is closed to new replies.