WordPress.org

Ready to get started?Download WordPress

Forums

Is this actually possible? (7 posts)

  1. Kargo
    Member
    Posted 3 years ago #

    Hi guys, happy new year.

    My website is http://www.escdaily.com and as you can see, the TOP STORY block has a blue background with white text. It displays the most recent article, regardless of category. What I would like to do, if its even possible, is to have the blue background change to red if the post has been made in a certain category.

    For example,
    Category: Default = Blue Background
    Category: Special = Red Background

    I'm using the Playmaker theme, but this is the code. Is it possible to do this, adding something in the CSS?

    [Code moderated as per the Forum Rules. Please use the pastebin]

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    post_class()
    http://codex.wordpress.org/Function_Reference/post_class

    using post_class in the post div would certainly generate category dependant css class(es)

  3. kaedues
    Member
    Posted 3 years ago #

    Yup. The implementation section in the codex page that alchymyth has linked to has a very good example that should explain how to do it. If you need more help, feel free to ask and we can help you out further!

  4. Kargo
    Member
    Posted 3 years ago #

    Thank you everyone :)

    I've just read the codex and tried it out for myself but I seem to be getting a syntax error each time so I'm guessing ive done something wrong.

    here is the code of the 'Top Story' section that I'd like to change colour
    http://wordpress.pastebin.com/iiGdHeaZ

    What would I need to add to the CSS? Just something like this?

    .category-79 {
    
    	background: #8b0000;
    
        color: #fafad2;
    
    	font-size: 22px;
    
    	line-height: 26px;
    
    	}
  5. Rev. Voodoo
    Volunteer Moderator
    Posted 3 years ago #

    <div class="topstory">

    this line here could be changed to:

    <div <?php post_class('topstory'); ?>>

    Which will keep your topstory class as I'm sure it's used for styling, but will also get you optional classes including one like category-79 which you can style as you have suggested....but be specific enough in your css to only target that cat in that area....

    .topstory .category-79

  6. Kargo
    Member
    Posted 3 years ago #

    Thank you for posting ^

    I have added the code you suggested and it seems to work with no errors although the colours are still not showing.

    I added

    [CSS moderated as per the Forum Rules. Please post a link to your site instead.]

    but still its showing up the default blue when I post in the selected category. Am I doing something wrong?

  7. Kargo
    Member
    Posted 3 years ago #

    Apologies mods.
    http://www.escdaily.com

    I added the code above and the styling suggested to my CSS but still the colour isnt changing. Am I doing something wrong?

Topic Closed

This topic has been closed to new replies.

About this Topic