Viewing 8 replies - 1 through 8 (of 8 total)
  • Michael

    (@alchymyth)

    try using the post_class() output which already outputs tag specific css classes to the post’s element;
    http://codex.wordpress.org/Function_Reference/post_class

    Thread Starter Tech4Eleven

    (@tech4eleven)

    ive been looking at that class but its not making much sense. any more direction?

    what Im basically looking to do is:

    if tag (or tag array), apply this class

    Michael

    (@alchymyth)

    btw: the example link is asking about category archives – you seem to be asking about single posts.

    Trying right now to call has_tag or even is_tag as laid out on the codex but it’s not working.

    what does ‘not working’ mean in more details?

    there are no other options, unless you work with ‘post_class()‘…

    for conditionals, see http://codex.wordpress.org/Conditional_Tags#A_Tag_Page

    is_tag() checks if this is a tag archive page, of the particular tag(s);

    has_tag() checks if the post has this tag/these tags

    I’m looking for a way to change the background color of the_content on my posts based on the post’s tag

    back to post_class():

    for a post with the tag ‘illusion’ this function would output the css class .tag-illusion;
    which you would use in css (assuming it is not overwritten by another more specific style):
    .tag-illusion { background: green; }

    what theme are you working with?
    does the theme use post_class() for the post element?
    can you link to an example post?

    Thread Starter Tech4Eleven

    (@tech4eleven)

    I am working with strappres. its trying to build in a custom solution so asking here. Within strappress, I am working with a custom post type. here’s my custom post type template code: http://pastebin.com/FcDs0Kg2

    I posted the entire template so you can see what I’m working with but the section that prints the post on the page, I have commented with “<!–THIS BEGINS MY POST BOX, INCLUDING TITLE AND CONTENT OF POST –>”

    If I add a background color in the css to .menu-container then it colors all the boxes, but that makes the background for all posts the same.

    This screenshot shows my site: https://dl.dropboxusercontent.com/u/1518168/2013-04-17_125407.jpg

    sorry I cant post the url. Im building the site with the theme test drive plugin. But in the screenshot, you see that the custom post type template (code above) pulls in these posts. the buttons on top left are the tags of the posts so when you click on one, it shows those posts – works like a filterable gallery. So for each post tag, Id like to that that tags posts have a different background color.

    I thought I was close with a tutorial like this: http://wpsnipp.com/index.php/css/add-custom-body-class-for-specific-pages/

    And whats not working, is the background color. everything I try doesnt apply any background color to the posts, whether here in the custom post type of the single post. Thanks for helping.

    Michael

    (@alchymyth)

    are you using a custom taxonomy?

    then look into:
    http://codex.wordpress.org/Conditional_Tags#A_Taxonomy_Page

    is this line:
    91. <li class="span<?php echo ($pcount); ?> <?php echo strtolower($tax); ?> block">
    your attempt to output term specific css classes to the content list element?

    if so, what it the output?
    is that reflected anywhere in the stylesheets?

    unfortunately, without a live link, any help with formatting issues is very limited.

    Thread Starter Tech4Eleven

    (@tech4eleven)

    ok, this is really stupid and really awesome at the same time. but while trying to implement your ideas above, I discovered that I didnt to change the custom post type template at all but all I need to do was to add a class to my css!! I had been using the exact slug what wordpress gave me in the dashboard for my tags but when I looked at the code, all the words in the slug where separated by dashes, for some reason, so in the dashboard for the tags, it listed:

    tag name: Specialty Sundaes
    slug: specialtysundaes

    but the code was saying “specialty-sundaes” so when I added a class for .specialty-sundaes in the css, it worked perfectly. I dont understand that but Im glad its working.

    thanks for your help.

    Hi there, I’ve also been trying to find a way to change the background colour of my posts if there is a tag called ‘featured’. Would you mind sharing the exact code you used to do this? I’m afraid I wouldn’t know where to start!

    Thread Starter Tech4Eleven

    (@tech4eleven)

    @swan1305 – if you use Firebug or Chrome Console, you can look at the code of your post and see if there’s a common class being generated. For me, my site generated classes according to the post’s tag, so I was able to write some simple css:

    .tag-class {background-color: #color}

    See my use of it here: http://www.armadillosicecreamshoppe.com/menu/ice-cream/

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display post background color based on post tag’ is closed to new replies.