Created
August 6, 2013 21:16
-
-
Save mikemurray/6168722 to your computer and use it in GitHub Desktop.
Grid system row assistance for loops.
This file contains hidden or 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 | |
// 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 ?> |
This file contains hidden or 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 | |
// 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