[resolved] different background color for different categories (5 posts)

  1. dulldesign
    Posted 7 years ago #

    for my blog, i have 4 main categories - 1) the right, 2) the wrong, 3) the past, & 4) the future.
    how do i change the background color of each post according to the categories?

  2. dulldesign
    Posted 7 years ago #

    anyone that can help?

  3. Chris_K
    Posted 7 years ago #

    One thought: Perhaps you could use something like the get_the_category template tag within The_Loop. A little PHP logic to then set a CSS class name for the content?

    There are also plugins that exist for "category pages", but from your question I can't determine if you're concerned with lists of posts, single post view and/or both.

  4. dulldesign
    Posted 7 years ago #

    it's for the lists of posts.

    i want different color for the background color of the header on the post.
    that way, people can tell what this post is about right way.

  5. dulldesign
    Posted 7 years ago #

    thanks chris!

    i did the get_the_category thing as your suggested. then i put down the color # on the category description. then i just used this code:

    foreach((get_the_category()) as $category) {
        echo $category->category_description  . ' ';

    it works perfectly! thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic