The above prints HTML with your added class and the defaults:
[html]<div id="post-4564" class="class-name post-4564 post type-post status-publish format-standard hentry category-news">[/html]
To print post_class CSS classes for a post other then the current one, specify its ID (integer):
<?php post_class( '', 22 ); ?>
The above prints (depending on category and tags): class="post-22 post type-post status-publish format-standard hentry category-another-cat tag-tag1 tag-tag2
Example of the template tag (and its default CSS classes).
This example shows the post_class template tag as commonly used in a theme file (such as single.php):
The output of the above prints this HTML (for a post in the ‘news’ category and a theme that supports Post Formats):
[html]<div id="post-4564" class="post-4564 post type-post status-publish format-standard hentry category-news">[/html]
Using these CSS classes you can then style this specific post, or all posts assigned the same category (or post format):
.post {
/* Styles for all posts */
}
.post-4564 {
/* Styles for only this post (ID number 4564) */
}
.category-news {
/* Styles for all posts in the 'news' category */
}
.format-standard {
/* Styles for all posts assigned the post-format of 'standard' */
}
Add more classes.
You can add a class to the
post_classdefaults:The above prints HTML with your added class and the defaults:
[html]<div id="post-4564" class="class-name post-4564 post type-post status-publish format-standard hentry category-news">[/html]
Use an array to add multiple classes:
To print
post_classCSS classes for a post other then the current one, specify its ID (integer):The above prints (depending on category and tags):
class="post-22 post type-post status-publish format-standard hentry category-another-cat tag-tag1 tag-tag2Example of the template tag (and its default CSS classes).
This example shows the
post_classtemplate tag as commonly used in a theme file (such assingle.php):The output of the above prints this HTML (for a post in the ‘news’ category and a theme that supports Post Formats):
[html]<div id="post-4564" class="post-4564 post type-post status-publish format-standard hentry category-news">[/html]
Using these CSS classes you can then style this specific post, or all posts assigned the same category (or post format):
A simple way to add multiple classes to the
post_classdefaults, is to just write them as a string argument:which will add those classes to the default class list.
post_class filter
You can also add classes using the
post_classfilter.