Skip to content

Instantly share code, notes, and snippets.

@mikemurray
Created August 6, 2013 21:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikemurray/6168722 to your computer and use it in GitHub Desktop.
Save mikemurray/6168722 to your computer and use it in GitHub Desktop.
Grid system row assistance for loops.
<?php
// Loop Variables
$max_per_row = 2;
?>
<?php for($i = 0; $i < count($data); $i++): ?>
<?php if($i % $max_per_row == 0 || $i == 0): ?>
<div class="grid-row"> <!-- Start Grid row -->
<?php endif ?>
<!-- Place grid columns here -->
<?php if($i % $max_per_row == 0 && $i > 0): ?>
</div> <!-- /grid-row -->
<?php endif ?>
<?php endfor ?>
<?php
// Loop Variables
$post_count = 0;
$max_per_row = 2;
?>
<?php foreach($data as $key => $value): ?>
<?php if($post_count % $max_per_row == 0 || $post_count == 0): ?>
<div class="row"> <!-- Start Grid row -->
<?php endif ?>
<!-- Place grid columns here -->
<?php if(++$post_count % $max_per_row == 0 && $post_count > 0): ?>
</div> <!-- /grid-row -->
<?php endif ?>
<?php endforeach ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment