Skip to content

Instantly share code, notes, and snippets.

@About2git
Forked from srikat/functions.php
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save About2git/a60e906c1fb5c66015df to your computer and use it in GitHub Desktop.

Select an option

Save About2git/a60e906c1fb5c66015df to your computer and use it in GitHub Desktop.
Alternate border colors for Posts in WordPress
//* Add even/odd post class for Posts in Posts page, Archives and Search results
add_filter( 'post_class', 'sk_even_odd_post_class' );
function sk_even_odd_post_class( $classes ) {
global $wp_query;
if ( is_home() || is_archive() || is_search() ) {
$classes[] = ($wp_query->current_post % 2 == 0) ? 'odd' : 'even';
}
return $classes;
}
.odd.entry {
border: 5px solid #288eb0;
}
.even.entry {
border: 5px solid #eeac18;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment