Use ‘post_class‘ for custom CSS per post.
An example with 3 variations (only use 1):
<div id="post-<?php the_ID(); ?>" class="red box" ?>> //idea 1
<div id="post-<?php the_ID(); ?>" <?php post_class('box-color'); ?>> //idea 2
<div id="box-color" <?php post_class(); ?>> //idea 3
<h3>Header</h3>
Content
</div>
To be able to choose a color in the post, use a custom field conditional.
http://codex.wordpress.org/Custom_Fields
To just change it based on category and such wrap the post class examples above in a category conditional.
http://codex.wordpress.org/Conditional_Tags#A_Category_Page
The logic ( not proper code but ya):
if in_category( array( 1,2,3 ) ) {
// add your custom post class div
}else{
// use default post class style.
Related Posts:
- adding a custom css class to post
- Is this the best (and only) option to style CSS for a given post type?
- Add a class to post title if a link ends with a certain extension
- Making a custom Pagination for multi page blog post
- Every second post different class in blog view
- How can I add a class to particular paragraphs in my post?
- Turn off display for custom sidebar post widget when on the post it’s displaying
- Enable Comments Box On Custom Post Type
- wp-cli post create & media import issues
- How can i limit the number of posts created per category?
- Search results posts_orderby and ID
- Getting Custom Post Loop to display in Bootstrap 3 column grid
- Turn On Comments On Custom Post Types in Directory Theme
- WordPress custom Query for Posts in Category display posts multiple times
- Responsive images with custom image size
- Can I search posts and pages for css classes?
- ERROR: Your feed is invalid (after update WP4.7) in custom types
- Editing the default page to show all posts, rather than most recent ones
- Unable to restore from backup – how to obtain old blog posts?
- Automatically add date to the auto generation of post slug
- Permission issue with custom post type – not added to menu – by plugin
- Duplicate Custom Post Type and Taxonomy Slug
- How could I change my Permalink from blog to custom structure? [closed]
- Remove Custom Post Type Slug and add Custom Taxonomy to Permalink Structure?
- Take a received feedback item, turn it into a post
- Getting value from get_post_custom
- WP Admin register taxonomy and post type performance
- Add a custom meta box in the post options that loads some html code in the header
- Static posts page with home.php
- Calling Different Custom Post Timestamps in a table
- WordPress Multisite – Create Default Post and New Category On New Site Install
- Admin – create custom post status and display above table
- custom post template file not shown, instead all the time 404.php
- Set Default Category to Username
- How to allow visitors to filter posts by multiple taxonomies
- How to add tags (custom taxonomy) to post class css?
- show custom post type category dropdown sorting result on same page
- Custom Post Type Rewrite To Include Parent Page(s)
- Thumbnail & Category link aside post
- Redirect to another page using contact form 7? [closed]
- Is there a way to specify an extra class for a post or page with no title?
- How to remove in-line style of WordPress’s post content only?
- How to include my own css in post
- Custom post types related to same custom post type?
- How do I insert a post with custom post type and relate it to a custom taxonomy?
- Dynamically switch template on click
- Add $values to post_class()
- “about us”, ” contact” sections should be article(post) or page in the simple small Business website?
- Is it possible to customize the post according to post format in single.php?
- Customize rel=canonical tag for single blog post
- a little direction on custom post type
- Grid post page on WordPress with Bootstrap, the_excerpt(); Problem
- disable Tab post on nav-menus page (Admin)
- Format latest/newest post differently
- Custom taxonomy archive page problem
- Make a vertical dynamic list of posts in alphabetically order and in columns [closed]
- Tell WP to use a specific template file in posts
- Is there a way to create a meta box that can be added multiple times to a post dynamically?
- relating business and products with custom taxonomy?
- Best Way to Add UnEditable HTML to Posts
- How to make different custom post layouts?
- How safe is it to delete old posts edits to save database space?
- Is there any way to stylize articles one by one?
- Two Custom Post Types with Identical Articles Competing for the same Slug
- Custom Post Type archive
- WordPress custom post type with folder structure in slug
- Using setup_postdata() with multi-dimensional array
- Font shows up as Arial instead of Times [closed]
- Is codex right on deleting post?
- Check if a custom post type has already been created
- WordPress Query Posts From Category Post on Static Page
- Edit multiple custom post types while saving a new or edited post
- Create a custom posts page
- How to add automatically bootstrap 4 order-lg-1 and order-lg-2 classes for columns in foreach loop based on the count?
- if in category but only with post meta
- How to style archive post titles… but only those posts who have comments?
- How to get different Related Posts
- How to add convenient buttons for new custom post statuses
- How to allow multiple thumbnail upload for Posts?
- add external project to web site wordpress on production
- Deleted a user with administrator rights. Now all the data/content/images are lost. how to recover them back
- My Custom Post Type Still Using index.php
- Show custom post with custom categories with specific slug
- register_post_type permalink
- Display the 2nd category name of a custom post type without error if its null?
- Auto delete posts based on content text
- How to call posts under a specific category on static front page?
- Querying another post category to match current post and display in loop
- Custom home page with full post for first one only
- Custom Post Limit for homepage only without plugin?
- Display value of custom field at the beginning of a post
- add div after image in post [closed]
- l accidentally permanently deleted a Draft. There’s any way I can recover it?
- datepicker value in mysql
- How do I switch css class on post
- Inserting an example of the last 3 post on to the homepage
- Microformats in a single post – layout conflict
- Static pages not working
- wordpress add field to post_class
- Optimize CPT-function with a loop