WordPress.org

Support

Support » How-To and Troubleshooting » how to CSS select all posts in a category

how to CSS select all posts in a category

  • It seems very straight forward in pages to CSS select all the child pages of a parent.
    such as: .page-child.parent-pageid-119

    I cannot seem to figure out how to select all the posts within a category, is this possible?

    thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • Have you tried using Firebug addon in Firefox browser?

    I have been using Inspect Element in Chrome, but tried Firebug as well.

    It is not under body class like it is for the pages

    Well eg for posts in the category “safety” I have

    <body class=”archive category category-safety category-10 logged-in admin-bar custom-background custom-font-enabled single-author customize-support”>

    So there is the class “category-safety” created by WordPress in the body tag.

    Would that help?

    no you are talking about when you are looking at the category page, I am talking about if you click on one of the titles on the category page, that takes you to the post page.

    What I get there is:
    <body class=”single single-post postid-300 single-format-standard logged-in admin-bar full-width-content customize-support”>

    I want to be able to tell any single posts in that category to have the same CSS style no matter how many new posts are added in the category they will all have the style.

    I did achieve this with pages and parent pages, but I am not sure how to do this with the posts and categories.

    My individual posts have the category in the article tag:

    <article class=”post-3901 post type-post status-publish format-standard hentry category-safety” id=”post-3901″>

    eg you should be able to use “category-safety” to style each post that is in that category

    Moderator Michael

    @alchymyth

    Forum Moderator

    the body_class() does not output category classes in single posts; you might need to add a filter;

    http://codex.wordpress.org/Function_Reference/body_class
    http://codex.wordpress.org/Function_Reference/body_class#Add_Classes_By_Filters

    have a close look at the second example…
    possibly adapt it this way:

    // add category nicenames in body_class
    function category_id_class($classes) {
    	global $post;
    	if( is_single() ) {
    	foreach((get_the_category($post->ID)) as $category) $classes[] = 'category-' . $category->category_nicename;
    	}
    	return $classes;
    }
    add_filter('body_class', 'category_id_class');
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how to CSS select all posts in a category’ is closed to new replies.