WordPress.org

Ready to get started?Download WordPress

Forums

a different background for each category (4 posts)

  1. viniciusmunich
    Member
    Posted 2 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
    Member
    Posted 2 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
    Theme Diva & Forum Moderator
    Posted 2 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
    Member
    Posted 2 years ago #

    Hello,
    I found a question similar to mine in this post:
    http://wordpress.org/support/topic/different-background-color-for-different-categories?replies=5

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

    bgcolor="<?php
    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

Tags

No tags yet.