a different background for each category (4 posts)

  1. viniciusmunich
    Posted 3 years ago #

    Hello again guys,
    A client of mine asked me for a variety of backgrounds were randomly displayed on your blog. I managed to do using php.

    Now she wants a particular background is displayed for each category / a different background for each category.

    I can not imagine how I can do that.

    Can anyone help me?

    Sorry for my english

  2. nicosFR
    Posted 3 years ago #

    I've done this already, but I don't have the code right here.

    The idea is to have a php condition that detects which category you are in (search for get_the_category in the codex) and then load a CSS stylesheet that overrides your default background.

  3. esmi
    Forum Moderator
    Posted 3 years ago #

    If your theme's header.php template file uses the body_class() function, each category will have a class based on the category name. You can then use this to apply different backgrounds via CSS.

  4. viniciusmunich
    Posted 3 years ago #

    I found a question similar to mine in this post:

    As you can see, you had success using this code:

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

    How and where should I use it?
    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.