0

UPDATE: I think this already may be in place, as i am able to assign icons to individual categories?

enter image description here

I am trying to customize a WP theme and I need different categories to be different CSS classes.

Example:

WP Category: Articles > class="cat-1"
WP Category: Blogs > class="cat-2"
WP Category: Press Releases > class="cat-3"
WP Category: News > class="cat-4"

I need to be able to style these differently. I am familiar with HTML/CSS but unfortunately I don't know much about PHP.

Can anyone help?

Thanks!

1
1

If your template uses the function post_class() in it then your posts already have category-based classes applied to them in the HTML. In PHP, it often will look like this:

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

For example, say you have a category of news, then posts that are in it will have a class of category-news among others. It also will have classes for tags as well like tag-{slug} as well.

So in your CSS you can simply use .category-news or whatever the slug of your category is.

.category-news {
   background-color: #123;
}

And so forth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.