Often when designing a WordPress theme, designers choose to have different styling for odd/even comments. Recently while working on a design, we decided to have different styling for odd/even posts. To do this, we needed to add an odd/even class to appropriate posts. Sadly, this is not one of the default classes. In this article, we will show you how to add an odd/even class to your posts in WordPress Themes.
Simply paste the following code in your theme’s functions.php file
function oddeven_post_class ( $classes ) {
global $current_class;
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
return $classes;
}
add_filter ( 'post_class' , 'oddeven_post_class' );
global $current_class;
$current_class = 'odd';
Now simply style the odd/even class differently. You are good to go.
Source: Kevin Chard








How could I take this a step further and target a specific post category?
I have a custom post type – testimonial, and I only want odd/even styling in that section.
Thanks!
You would have to use WordPress conditionals:
http://codex.wordpress.org/Conditional_Tags
This is by far the easiest method of creating odd and even posts for wordpress!! Thanks so much for sharing!
As, sadly, css3 selectors are not well supported by all browsers…
I just tried your code for a new twenty eleven child theme i’m customizing, it works so fine,
Thanks a Lot for sharing this ! !
What is odd/even class ? Sorry but i’m newbie
@Daniele Zamboni These are CSS classes that you can add for styling purposes.