Skip to content

Instantly share code, notes, and snippets.

@bryceadams
Last active January 13, 2018 17:01
Show Gist options
  • Save bryceadams/6e0c70f66f1235c08355 to your computer and use it in GitHub Desktop.
Save bryceadams/6e0c70f66f1235c08355 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