Skip to content

Instantly share code, notes, and snippets.

@neilgee
Last active May 16, 2017 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save neilgee/9b8ff48c0b5cbe8845fb to your computer and use it in GitHub Desktop.
Save neilgee/9b8ff48c0b5cbe8845fb to your computer and use it in GitHub Desktop.
Odd/Even Post Class in WordPress
<?php //<~ dont add me in
add_filter( 'post_class', 'themeprefix_odd_even_classes' );
function themeprefix_odd_even_classes( $classes ) {
global $wp_query;
if($wp_query->current_post % 2 == 0) {//http://stackoverflow.com/questions/7959247/php-test-if-number-is-odd-or-even
$classes[] = 'odd';
}
else {
$classes[] = 'even';
}
return $classes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment