Support » Themes and Templates » Different Colour Dates Based on Categories

  • Hi,

    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

Viewing 2 replies - 1 through 2 (of 2 total)
  • esmi

    (@esmi)

    Forum Moderator

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

    Eg:

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

    CSS:

    .personal {background-color:green;}
    .portraits {background-color:pink;

    Thank you that worked fantastically! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Different Colour Dates Based on Categories’ is closed to new replies.