Display images by upload info1 record

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 12, 2019   (RSS)

By degreesnorth - February 11, 2019

Help - anyone?

By daniel - February 12, 2019

Hi degreesnorth,

Yes, this sort of thing is definitely possible.

First, to only display images with a specific value in the info1 field, you need to add some code to the beginning of the image loop. It would be something like this:

<?php foreach ($exampleRecord['images'] as $index => $upload): ?>

  <?php if ($upload['info1'] != 'summer') { continue; } ?>

  ...

<?php endforeach; ?>

The above will skip all records that don't have "summer" in info1. (You'll need to update the variable names to match your code)

Then, to pick only 8 images at random, we can shuffle the image array, and use a counter to make sure we only display 8 images:

<?php shuffle($exampleRecord['images']); ?>
<?php $imageCount = 0; ?>
<?php foreach ($exampleRecord['images'] as $index => $upload): ?>

  <?php if ($upload['info1'] != 'summer') { continue; } ?>
  <?php if ($imageCount++ >= 8) { break; } ?>

  ...

<?php endforeach; ?>

Let me know if that helps!

Thanks,

Daniel
Technical Lead
interactivetools.com

By degreesnorth - February 12, 2019

Hi Daniel

That works perfectly, thank you heaps!

Cheers

Carole