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 have 2 categories, just to make an easy example, Cars and Bikes. I have a post that fits both of the category. If i visit the Cars category, the body_class looks like this:

"archive category category-cars category-1 category-cars category-bikes"

The problem is that somehow the post category is visible in the body_class after the category-1 classname. How can i avoid this? I need to use different colors for different categories, but right now the category-bikes class overwrites the category-cars class.

share|improve this question
add comment

1 Answer 1

This could be solved via CSS as well. Just set up declarations for the special cases where there is overlap between categories:

.category-cars { background-color: #f00; }
.category-bikes,
.category-cars.category-bikes { background-color: #0f0; }

This will give any posts that are in both bikes and cars the same background color as those used in the bikes category.

share|improve this answer
    
Yes, but i have 9 categories, so this solution is not exactly what i am looking for. But thanks:) Maybe i just remove the body_class function and add the category slug to the body... –  passatgt Jul 25 '12 at 15:32
    
I just duplicated the get_body_class function to my functions.php, and if i change return apply_filters( 'body_class', $classes, $class ); to return $classes, it works fine. I guess something is using a filter to hook up those extra category classes, but i can't find it anywhere... –  passatgt Jul 25 '12 at 16:03
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.