Skip to content

Instantly share code, notes, and snippets.

@sauliuz
Last active December 15, 2015 13:49
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 sauliuz/5270330 to your computer and use it in GitHub Desktop.
Save sauliuz/5270330 to your computer and use it in GitHub Desktop.
Check if WordPress post number is even or odd. And running some actions based on findings
<?php
// First we need to set counter
$postnum = 1;
// Running WordPress loop to get all posts
if (have_posts()) :
while (have_posts()) : the_post();
// Time to check if post number is even or odd
if ($postnum&1) : ?>
<!-- do some actions if number is odd -->
<div class='row'></div>
<?php
endif;
// Increase the counter
$postnum++;
endwhile;
endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment