Skip to content

Instantly share code, notes, and snippets.

@phlbnks
Last active September 7, 2016 19:34
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 phlbnks/d6df6c9c6d0edbaa45230197f15929fa to your computer and use it in GitHub Desktop.
Save phlbnks/d6df6c9c6d0edbaa45230197f15929fa to your computer and use it in GitHub Desktop.
Modulus example to create rows in a grid
<div class="row">
<?php
// $posts is some content to loop over and output.
$posts_count = 0;
foreach ( $posts as $post ) :
echo $post;
if ( $posts_count % 3 == 2 ) : // Fires every 3rd item since we are counting from 0. ?>
</div><div class="row>
<?php endif;
$posts_count++;
endforeach;
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment