Login | Sign up | Toll-Free: 1-800-752-0455
 
 

Forum

 

3 posts by 2 authors in: Forums > CMS Builder
Last Post: March 8, 2018

Is there a way to randomly show three images on a Detail Page from an upload with a max of six?

Shuffle is cool but it shows all the uploads.

Thanks

Terry

Hi Terry, 

If you don't have too many uploads maybe you could just load them all and use a counter to only show the first three? 

  <?php // simple counter cutoff
    $fruits = ['apples','oranges','pears','peaches','kiwis','strawberries'];
    shuffle($fruits); // random order
    $count = 0;
    $max   = 3;
  ?>
  <?php foreach ($fruits as $fruit): ?>
    <h1><?php echo $fruit; ?></h1>
    <?php if (++$count >= $max) { break; } ?>
  <?php endforeach ?>

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com