Need help? Check out our Support site, then


Twenty twelve: category classes in article not body

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

  2. philiparthurmoore
    Member

    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.

  3. Incidentally, in looking through themes, I have discovered the degree to which theme structure and classes have been made more consistent during the past year or two. Pretty nice!

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

    However, perhaps others have had this particular need and know of a theme which doesn't follow that protocol.

  4. philiparthurmoore
    Member

    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.

    Cheers.

  5. The site is still in private development, but I have invited you to view.

    Here is the site: http://mainedoeupdates.wordpress.com/
    Here is a category archive: http://mainedoeupdates.wordpress.com/category/programs/social-studies-updates/
    Here is an single post in that category: http://mainedoeupdates.wordpress.com/2012/10/31/cross-discipline-literacy-network-registration/

    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.

    Hope that helps.

  6. philiparthurmoore
    Member

    Thanks. It's midnight here (I live in Hanoi) so I'll have to pick this up again in the morning. I'll update this thread as soon as I've given everything a look for you.

  7. Of course! Thank you so much for your time. See you tomorrow.

  8. philiparthurmoore
    Member

    By the way, you don't need to invite me to your site (you can cancel the invitation). I'm able to see it at all times, regardless of its privacy status. I'll be in touch soon!

  9. Thanks!

  10. philiparthurmoore
    Member

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

  11. I understand, and that's what I thought.

    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.

    Thank you for looking into this.

  12. philiparthurmoore
    Member

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic