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.