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.

I was wondering if there's any way to discover which categories are "active" on a category archive page. This is for the purpose of menu highlighting.

To demonstrate, compare these:

(1) Parent category archive: http://building.mediumutm.ca/test-cat/ In the menu, the category is highlighted because it's active - cool. But so are both the dropdown menu links, its subcategories.

(2) Post in the parent category: http://building.mediumutm.ca/post-test-cat/ Working perfectly. Only the parent category is active and highlighted, not the dropdowns.

So it's really only (1) that's a problem, and I suspect it's not a CSS class issue because (2) works fine... So it that that archive page treats the subcategories as active? If so, can I disable that? Or what?

Thanks!

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Alas, this is a CSS issue, caused by some difference in WP's classes applied. :)

First you are misinterpreting your "test" case 2:

  1. Dropdown isn't highlighted because (despite what post body says) it's not actually assigned the subcategory.
  2. The styling applied is from .current-menu-parent, since post is obviously not a term in taxonomy.

In your first case the class at work is .current-menu-item, since we are looking at the term in taxonomy. Next the CSS rules .current-menu-item a applies to all links inside of it and since dropdown HTML is inside top level item HTML it all gets styled as "current".

You should be limiting such rules to immediately nested links inside container — .current-menu-item > a (which is already done correctly for .current-menu-parent > a).

share|improve this answer
    
Brilliant, thanks! And now I learn about child vs. descendant. –  TheMediumUTM Aug 21 at 16:46

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.