alex-fever
Member
Posted 1 year ago #
Hi everyone,
I'm trying to figure out how to style the category links with different colours. I'm using the post_class function to generate dynamic classes - which works fine when only one category is assigned to a post - but when two or more categories are assigned the links inherit the classes and get the same styling.
How can i separate the classes so that each category link has a unique css style?
Here's a link to a screenshot which hopefully illustrates what the heck I'm going on about :)
Any help is greatly appreciated!
-Alex
alex-fever
Member
Posted 1 year ago #
For anyone interested I worked out a solution by using the "CSS atrribute selector" to target each tag-links' title attribute - wordpress automatically adds a title of:
title="View all posts in (category name)".
So I targeted each category with a css selector like this one, to target all links with a title attribute containing the word "Design":
#yourselector[title~=Design]
----
If anybody has a better solution - or workaround - feel free to add it in here!
-Alex
Blake Imeson
Member
Posted 11 months ago #
I was trying to do the same thing and ended up using this code in a "Recent Posts" widget.
<a class="<?php $category = get_the_category(); echo $category[0]->cat_name; ?>" href=...
I wrote up a little more on it on my blog:
Style Links with CSS by Category – WordPress