Category Link Colors (5 posts)

  1. salromano
    Posted 4 years ago #

    I need a hack or plugin that will allow me to change the link color of a category displayed in a certain area.

    For example, if I have a post:

    by Author


    Listed in: Cat 1 (<- this would be red), Cat 2 (<- this would be green)

    Any ideas?

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    If your theme uses the body_class() function, you can do this using pure CSS.

  3. salromano
    Posted 4 years ago #

    New things are pretty easy for me to latch on to - what's the body_class() function and how could I use it to accomplish my goal?

  4. salromano
    Posted 4 years ago #

    I've been looking around. Here's what I've managed to put together from my findings:

    <?php $the_cat = get_the_category(); $category_link = get_category_link( $the_cat[0]->cat_ID ); foreach((get_the_category()) as $category) { echo '<a class="'.$category->slug.'" href="'.$category_link.'">'.$category->cat_name.'</a>' ; } ?>

    This way, it appears as such:

    <a href="http://website.com/category/category-1">Category 1</a><a href="http://website.com/category/category-2">Category 2</a>

    Then, you go into your CSS, and add the following:

    a.category-1 { color: #333; }
    a.category-2 { color: #CCC; }

    And so on.

    Only problem: I need a way to separate the categories by comma as they display.

  5. salromano
    Posted 4 years ago #

    Can anyone help me with the separation?

Topic Closed

This topic has been closed to new replies.

About this Topic