WordPress.org

Ready to get started?Download WordPress

Forums

different backgroundimages for each category on the mainpage (11 posts)

  1. Echnaton69
    Member
    Posted 8 years ago #

    hi,

    I've searched around but didn't find an answer.

    Is it possible (and if yes how? ;-) ) to show a different background-image (oder color) for an article on the main page where the image (or color) depends on the category the article is written in?

    for example a post on the mainpage from the category "fish" shows a blue background and a post from the category tree a green one.

    Thank you and

    kind regards from Vienna

    Andreas

  2. Orin
    Member
    Posted 8 years ago #

    If you wanted to have <img> tags put in for each category, it would be pretty simple to use the Category Images plugin. However, what I think you're seeking sounds like it'd be easier accomplished using php to define a unique class for each category, then assigning unique styles.

    <?php if (is_category('about')) { ?>
    class="cat-about"
    <?php } elseif (is_category('books')) { ?>
    class="cat-books"
    <?php } elseif ...
    (etc) { ?>
    <?php } ?>

    Learn more about conditional tags in the codex.

  3. skippy
    Member
    Posted 8 years ago #

    See also the Structured Blogging and Force Category Template plugins.

  4. ugua
    Member
    Posted 8 years ago #

    I did what Orin said.
    But it doesn't chanche anything in my site.

    Can u have a look please?
    http://www.sancarlobasket.com/wp3/

  5. dss
    Member
    Posted 8 years ago #

    In order to restyle your categories, you will need to write the css style for the code you want to add, or force in the conditional tag.

    Without the css in your style.css then changing the ID or CLASS won't make any changes.

    I would look into the Force Category Template solution and unless you're ready to change your styles around manually use various themes you like for the look of your categories.

  6. ugua
    Member
    Posted 8 years ago #

    well the css is here

    .cat-milan {
    background-color: #000000;
    border: 1px solid red;
    }

  7. ugua
    Member
    Posted 8 years ago #

    up

  8. Kafkaesqui

    Posted 8 years ago #

    Look at replacing the is_category() conditional Orin mentioned with in_category():

    http://codex.wordpress.org/Template_Tags/in_category

  9. dss
    Member
    Posted 8 years ago #

    yes, Orin and KAfkaesqui and right. I didn't read the initial entry clearly.

    That will totally work.

    Add the conditionals for the style into your header. and add the style for each cat within the conditional.

    <?php if (is_cat ('1')) { ?>
    css style for cat 1

    <?php else_if (is_cat('2')) { ?>
    css style for cat 2

    <?php else_if (is_cat('3')) { ?>
    css style for cat 3

    <?php } ?>

    I don't know if it's still true, but it used to be best to write conditionals for the category or post number, and not the name to avoid problems.

    Try this, and then add it to your header and I'll be it will work just fine.

  10. Kafkaesqui

    Posted 8 years ago #

    Actually, you want:

    <?php if (in_category('1')) { ?>
    css style for cat 1

    <?php else if (in_category('2')) { ?>
    css style for cat 2

    <?php else if (in_category('3')) { ?>
    css style for cat 3

    <?php } ?>

    I'm not sure what that is_cat() thing is... ;)

  11. ugua
    Member
    Posted 8 years ago #

    thank u guys it helped

Topic Closed

This topic has been closed to new replies.

About this Topic