WordPress.org

Ready to get started?Download WordPress

Forums

Different backgrounds on every category (8 posts)

  1. joebordo
    Member
    Posted 4 years ago #

    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

  2. Stian Andreassen
    Member
    Posted 4 years ago #

    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 ...

  3. joebordo
    Member
    Posted 4 years ago #

    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 ?

  4. Peter Boosten
    Member
    Posted 4 years ago #

    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.

    Peter

  5. Lara
    Member
    Posted 4 years ago #

    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 :)

    Lara

  6. Summerstrike
    Member
    Posted 4 years ago #

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

  7. SpankMarvin
    Member
    Posted 4 years ago #

    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.

    John

  8. Spencer Finnell
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic