Last active
December 15, 2015 13:49
-
-
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
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 | |
// 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