How To Add Odd and Even CSS Classes to WordPress Posts - WPTRINITY

How To Add Odd and Even CSS Classes to WordPress Posts

This code helps users visualize to adds an odd or even class to WordPress posts.

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'

You can now add custom CSS to style them differently. Here is a sample code to help you get started.

.even {
background:#f0f8ff;  
} 
.odd {
 background:#f4f4fb;
}

The end result will look something like this: