wordpress snippets last updated   : October 6, 2014
we now have 641 snippets

Alternate odd even post class

wordpress snippet

Adding this PHP code to your wordpress theme will append odd or even classes to post_class function.

snippet :  PHPcopy
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';

Did you like this post? If so please share it with your friends. Thanks!