[resolved] Styling category links differently (3 posts)

  1. alex-fever
    Posted 5 years 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!


  2. alex-fever
    Posted 5 years 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":



    If anybody has a better solution - or workaround - feel free to add it in here!


  3. Blake Imeson
    Posted 4 years 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

Topic Closed

This topic has been closed to new replies.

About this Topic