Skip to content

Instantly share code, notes, and snippets.

@ashleycam3ron
Forked from bryceadams/check-nth-post.php
Created January 13, 2018 17:01
Show Gist options
  • Save ashleycam3ron/0d6625d09cecb8d7b2fdf052cb5ee53c to your computer and use it in GitHub Desktop.
Save ashleycam3ron/0d6625d09cecb8d7b2fdf052cb5ee53c to your computer and use it in GitHub Desktop.
check every nth post wordpress
<?php
// $the_query would just be a standard WP_Query
if ( $the_query->have_posts() ) :
$counter = 1;
while ( $the_query->have_posts() ) : $the_query->the_post();
if ( $counter % columns == 1 ) {
// do something at the start of your 'row'
}
// some content
// Check if $counter/$columns is equal to an integer
if ( is_int( $counter / $columns ) ) {
// do something at the end of your 'row'
}
$counter++
endwhile;
// Reset WP_Query() data
wp_reset_postdata();
endif;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment