Twenty twelve: category classes in article not body

For single posts, I see that category classes are included in the article tag, but not in the body tag. I believe that prevents us from hiding or displaying widgets based on the category, since the sidebar widgets appear in a different part of the HTML tree.

Are there any ways to use a non-inherited class in a different part of the CSS? Alternatively, are there any themes that place the category CSS class in the body tag rather than the article tag? (I've been looking with no success thus far.)

Howdy jcollier. Can you give me a bit more specific information about what you're trying to accomplish? What's the site you need help with? Can you give me the link to a single post view of your page and also tell me where you're trying to hide/display your widgets? Cheers.

Perhaps that explains why I am finding the application of category classes to the article tag pretty standard.

I'm pretty sure this is a Core thing, not just a WordPress.com thing. For example, the output of a single post in Twenty Twelve will give classes directly from post_class(). It doesn't matter what theme you're using; classes for categories will be added to primary post wrappers if post_class() is used.

I would like to have a category specific widget appear on both the category archive and single post in that category.

This works on the category archive, since the class "category-social-studies-updates" appears with the body tag and can be inherited by the sidebar (aside).

However, on a single post, that category class appears in article rather than body, so it cannot be inherited by the sidebar widget. Therefore, I don't know if we can hide or display that widget based on category.

Hi again. I totally see what you're talking about now. Sadly, I don't think it's going to be possible to do this in an automated fashion; you'd need to manually hide or show the widget using the post-specific body class postid-1663. I know this would be a total pain to handle manually, but there's simply no way to automate this because of where the category class is placed (which is normal behavior for WordPress, not just Twenty Twelve).

I remember that, in the past, some themes included the category class in the body tag as well. I'd be interested in finding out why that isn't done any more, so if you have suggestions as to how I might raise that question, I'd be obliged.

I'd be interested in finding out why that isn't done any more, so if you have suggestions as to how I might raise that question, I'd be obliged.

I really think this is a theme-by-theme case, to be honest. I know that the themes we're developing in-house are all based on _s and it, as well as many, many themes today just use body_class to spit out classes on the body. I imagine that this issue rarely comes up for self-hosted blogs, and for managed hosting like WordPress.com, we want to keep our code as clean and as close to how Core is handling it (so not programming in extra classes on the body as much as possible).

Sorry I don't have a 100% perfect answer for you, but I'll mark this resolved; please feel free to open up another thread if you run into any more problems. Have a good one.