Skip to content

Instantly share code, notes, and snippets.

@dospuntocero
Created September 9, 2018 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dospuntocero/1b5a6e16267c7efed6a88b9a07cfd949 to your computer and use it in GitHub Desktop.
Save dospuntocero/1b5a6e16267c7efed6a88b9a07cfd949 to your computer and use it in GitHub Desktop.
even odd classes on wordpress loop example on line 10 / 13
<?php
// WP_Query Arguments
$args = array(
'order' => 'DESC',
'posts_per_page' => 5
);
// The Loop
$query = new WP_Query( $args );
while ( $query->have_posts() ) : $query->the_post();
$even_odd_class = $wp_query->current_post % 2 == 0 ? 'even' : 'odd';
?>
<div class="<?php echo $even_odd_class; ?>">
<p>Some content</p>
</div>
<?php endwhile; wp_reset_postdata(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment