Skip to content

Instantly share code, notes, and snippets.

@betweenbrain
Last active December 17, 2015 21:08
Show Gist options
  • Save betweenbrain/5672035 to your computer and use it in GitHub Desktop.
Save betweenbrain/5672035 to your computer and use it in GitHub Desktop.
Wrap K2 Items in "row" elements
<?php
$count = count($this->leading);
if (isset($this->leading) && $count) :
?>
<div class="item-list">
<!-- start first row -->
<div class="row">
<?php foreach ($this->leading as $key => $item) :
$fmod = fmod($key + 1, $this->params->get('num_leading_columns'));
?>
<div class="itemContainer">
<?php
// Load category_item.php by default
$this->item = $item;
echo $this->loadTemplate('item');
?>
</div>
<?php // Not last item, but end of row
if (($key + 1 != $count) && ($fmod == 0)) : ?>
</div><!-- end row -->
<!-- start next row -->
<div class="row">
<?php // Last item and end of row
elseif (($key + 1 == $count) && ($fmod == 0)) : ?>
</div><!-- end last row with no remainder -->
<?php // Last item, but not end of row
elseif (($key + 1 == $count) && ($fmod != 0)): ?>
</div><!-- end last row with remainder -->
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment