wordpress snippets last updated   : January 27, 2015
we now have 644 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!