WordPress.org

Ready to get started?Download WordPress

Forums

Different Colour Dates Based on Categories (3 posts)

  1. hmulholland
    Member
    Posted 4 years ago #

    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

  2. esmi
    Theme Diva & Forum Moderator
    Posted 4 years ago #

    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;
  3. hmulholland
    Member
    Posted 4 years ago #

    Thank you that worked fantastically! :)

Topic Closed

This topic has been closed to new replies.

About this Topic