If your template uses the function post_class()
in it then your posts already have category-based classes applied to them in the HTML. In PHP, it often will look like this:
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
For example, say you have a category of news
, then posts that are in it will have a class of category-news
among others. It also will have classes for tags as well like tag-{slug}
as well.
So in your CSS you can simply use .category-news
or whatever the slug of your category is.
.category-news {
background-color: #123;
}
And so forth.
Related Posts:
- Hide post meta data on a specific category
- Custom css per category and per single post belong in each category
- How to prevent page re-sizing for mobile browsers [closed]
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Gutenberg editor add a custom category as wrapper for custom blocks
- How can I hide a category from Contributors in the edit/add new post screen?
- WordPress Multiple Category Search
- How to remove categories filter from wordpress admin?
- Decreasing the Memory Consumption of a WordPress Site?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive
- How can I select a primary category?
- how to use a different domain/subdomain for authors/catagories on single site?
- Deleting default category in wordpress
- Delete a specific category when deleting a user
- How to list child categories in custom category template?
- Trash bin for categories
- How to set up sub-categories for author pages?
- View category in the preview of Theme Customizer
- Create a full width responsive header image per page
- One WordPress Install, Two Categories. Each Category Gets a Domain
- Block multiple categories from Blog
- Remove “Category Archives: title” at the top of a category page [duplicate]
- How to have a static category/author page?
- How to rewrite the post URL according to the category?
- How to build a simple nav system of custom post type categories and its posts?
- Style category link depending on category ID
- Inside a loop, how to change CSS class based on category name?
- Redirect to another page using contact form 7? [closed]
- Display thumbnails for certain category posts
- Why do I have stray bullet from
- Keyword search in multiple categories
- Is it possible to remove from default category widget?
- How to customize my category pages
- How to add custom color fields to the category edit page?
- How to make the ‘delete’ button inactive on some categories?
- Two columns in homepage each with one category
- Multiple selection for wordpress widget
- how to nest specific category thumbnails inside different containers
- Wrong category nice name is displayed on archive page
- Simple way to style posts of a single category differently in the loop and in single
- How can i change what one category displays?
- Remove any product that is featured from regular display loop [WooCommerce]
- Two Sections on Woocommerce Catergory Page [closed]
- Remove Archive | from Categories
- How to let the user create a selection of categories via the backend
- Theme for subcategories
- Add code to header based on category for specific posts?
- Restrict CSS on one page
- How to hide widget from certain category
- custom query for both category and pages using global $wpdb;
- I would like to feature a tip on the homepage
- Show Secondary Sidebar on Category pages (archive)
- How to add icon over specific thumb
- Problem with Custom Post Type Categories
- List post only under the category, exclude child category content
- SQL query to get posts from multiple categories but not in a category
- wp_delete_term or wp_delete_category?
- Select posts that match multiple category names, must match all categories listed
- Custom Portfolio Page
- Last x Posted Categories?
- I need advice on how to structure the categories according to the layout i have
- show only sub categories if available?
- How to get sub-categories to display same look as there parents
- How to add meta description, keywords, custom title to a category template
- separate posts to have (kind of) 2 blogs?
- category description not showing in my woocommerce
- Inline If statement to echo CSS [closed]
- Hide entry-header for a specific category
- How to “remove” WordPress categories UL and make the list loop in a horizontal line?
- problem with filter of custom portfolio categories
- Deleted categories still listed until additional page refresh
- How can I make a category function as a page?
- Category custom template is not showing correct posts
- Search Replace Database ONLY for posts of certain category?
- Default URL for category dropdown select option
- Filter custom taxonomy posts via AJAX
- Need help to structure our a complex hierarchy
- Inserting categories as a hierarchical terms from frontend form
- Show posts from all categories
- How to add a post with new Taxonomy without assigning to default category?
- Getting page/category content to show up in my custom page template
- How do you add Author and date Published on Category Pages?
- If it is a top level category show children otherwise show sibling categories
- Own Custom Tags/Category page ( posts)
- Gettind 404 not found wen click the view button for a given category custom post type portfolio
- How to create default categories in new installs?
- Custom CSS to resize elements in multiple categories
- display certain category on custom template page
- List all authors by matching custom meta data on a category page
- Custom Woocommerce Category view
- why is the delete option missing from just one category?
- Broken category styling
- How can i hide the authors box from a specific set of categories and post types?
- Custom permalinks structure
- Woocommerce custom taxonomy order
- How to hide my categories pages’ names, and how as well to reduce the space beween my sidebar’s widgets?
- Modifying posts based on category in TwentyTwentyTwo theme
- How can I get the categories and subcategories separately?
- Elementor : display only one category in loop grid
- change the listing type of categories block?