WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] different background color for different categories

[Resolved] different background color for different categories

  • 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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • anyone that can help?

    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.

    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.

    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:

    bgcolor="<?php
    foreach((get_the_category()) as $category) {
        echo $category->category_description  . ' ';
    }
    ?>"

    it works perfectly! thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] different background color for different categories’ is closed to new replies.
Skip to toolbar