I have a div whose background image changes according to my WordPress categories:
div.cat-links a.cat-log {
background-position: 20px 5px;
}
div.cat-links a.cat-a day in the life {
background-position: -163px 5px;
}
The code for the image is being reproduced here:
<div class="cat-links">
<?php foreach((get_the_category()) as $category) {
echo '<a rel="category-tag" href="'.get_category_link($category->cat_ID).'" class="cat-'.$category->cat_name.'">'.$category->cat_name.'</a>';
} ?>
</div>
In my example above it works for the first category, 'log', because it is a single word category. It doesn't work, however, for my category 'a day in the life'.
I am aware of threads like this but I'm struggling to implement it and would appreciate some help with this. Thank you.