-
-
Save hemusyl/012f5a0465b1991ca0e4916b0d02038b to your computer and use it in GitHub Desktop.
Odd/Even Post Class in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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