post_class()
function. Its quick, easy and painless.
To make sure that when you write <div <?php post_class(); ?>
, the post/entry divs will be given the alternating odd/even CSS classes, add the following to the functions.php
:
add_filter ( 'post_class' , 'butter_odd_or_even' );
if( !function_exists( 'butter_odd_or_even' ) ) {
global $current_class;
$current_class = 'odd';
function butter_odd_or_even ( $classes ) {
global $current_class;
$classes[] = $current_class;
$current_class = ($current_class == 'odd') ? 'even' : 'odd';
return $classes;
}
}