• I have image on each post and I want to add a banner that will show the category name of that post and a unique background color for that category. Using a span class I can specify a background color but it applies to all the banners and isn’t colored based on category.

    Is it possible to do this with one span class or would it be better to write a if/else clause for each category? My categories are easy digital downloads categories so they are called differently than normal categories.

    So far I have:

    ‘<div class=”campaign-image”>
    <?php if ( is_object_in_term( $campaign->ID, ‘download_category’) ) : ?>
    <span class=”category”><?php the_terms( $campaign->ID, ‘download_category’ ); ?></span>
    <?php endif ?>’

    and the css is

    ‘.campaign-image .category{

    }

    .bird { background-color:green !important; }
    .forest { background-color:blue !important; }
    .fossil { background-color:red !important; }’

    I thought maybe I could put something like
    ‘<span class=”category-<?php get_download_category ?>”>’

    Any advice would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Color the background based on category’ is closed to new replies.