Different Colour Dates Based on Categories (3 posts)

  1. hmulholland
    Posted 6 years ago #


    I am working on a new wordpress theme and I had the idea of having the background of the date box change with what category is attached to the post.

    IE - If the category is personal the background would be green, category portraits = pink. etc etc

    I don't know how I would go around doing that, or if it is possible. So I was hoping if some people could give me some insight.

    Thank you and I hope I explained it properly :S

    - Heather

  2. esmi
    Forum Moderator
    Posted 6 years ago #

    You could try adding an extra class using the in_category conditional in the relevant template file and then style that class.


    <?php  $xclass = '';
    if( in_category('Personal') ) $xclass .= ' personal';
    elseif( in_category('Portraits') ) $xclass .= ' portraits';?>
    <div class="date<?php echo $xclass;?>><?php the_date();?></div>


    .personal {background-color:green;}
    .portraits {background-color:pink;
  3. hmulholland
    Posted 6 years ago #

    Thank you that worked fantastically! :)

Topic Closed

This topic has been closed to new replies.

About this Topic