List split

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 17, 2015   (RSS)

By Daryl - November 17, 2015

Hi master,

You can achieve that by using a counter and add closing and opening li tags every 5 counts if the current array is not the last.
For example:

<div class="dates-wrapper">
  <ul>
    <li>
    <?php
    // get last record num
    $lastExampleRecord    = end($exampleRecords);
    $lastExampleRecordNum = $lastExampleRecord['num'];
    $counter = 0;
    ?>
    <?php foreach($exampleRecords as $record): ?>
      <div class="date-box"><?php echo $record['num'] ?></div>
      <?php
      // close <li> tag and open a new one every 5 records if this is not the last record
      if (++$counter >= 5 && $lastExampleRecordNum != $record['num']){
        print '</li><li>';
        $counter = 0; // reset counter
      }
      ?>
    <?php endforeach; ?>
    </li>
  </ul>
</div>

Hope this helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com