Support » Themes and Templates » Different backgrounds on every category

  • Hi everyone,

    I have a blog with 4 categories. Each Category has its own topic. So what i want is , to have different backgrounds for every category. So lets say if u click on category photoshop. you background changes to the background you specified. (If i could change the sidebar too it would be perfect) Also if someones click on a post the background should change to the background that was set to the category where the post belongs to.

    Is this possible ?

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • You can use is_category() for this.

    Say you have a <div> you want to change the background image for, then in the PHP you use:

    <div style="background-image: <?php
    if(is_category('Movies')) echo (get_bloginfo('stylesheet_directory').'/images/backgrounds/movies.jpg");
    if(is_category('Music')) echo (get_bloginfo('stylesheet_directory').'/images/backgrounds/music.jpg");

    Modify to fit your needs …

    Hi Stiand,

    Thx for your reply . I don’t understand wher i have to put the code u gave me ? i tried in my defaultindex and stylesheet.

    The background my blog is setting is set in the stylesheet css settings . . . can u give me more information how to use this ?

    Maybe it’s much easier than that: if your theme uses post_class() to fill the class for a post, then also a class exists per category.

    This class can then be used to create some custom css for.

    If you supply an URL, we could have a look.




    Hm…don´t like to dig, but could somebody please explain how to integrate this function? I don´t see where my template uses post_class() (i use Mistylook basically) and I don´t find the right position for the given code.

    Is it even possible to use html in the stylesheets? Might be a stupid question but I don´t really know how to code, I can hardly read it, so please don´t be harsh to me 🙂


    i hope there is someone who can give enlightenment with an easy explanation because I also have long to find the answer to this

    Give us a link to your site, preferably to two separate category listings. This should help us work out whether your theme is producing custom classes based on the category.


    Your theme should (hopefully) have body_class() applied to it. If it doesn’t, you should add it.

    Once you have that working, the body tag of each page will have some specific classes applied to it, such as category-x. You can then style these individually in your CSS.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Different backgrounds on every category’ is closed to new replies.