Show first 3 images only in upload field

4 posts by 2 authors in: Forums > CMS Builder
Last Post: November 13, 2009   (RSS)

By benedict - October 5, 2009

Hi guys,

I am using an upload field and I only want to show the first three images in it on a page sidebar (the rest of them appear in a slideshow gallery).

I've seen use of <?PHP BREAK>, but that only shows the first image. Any tips?

Cheers!

Re: [benedict] Show first 3 images only in upload field

By Chris - October 6, 2009

Hi benedict,

Something like this should do the trick:

<?php $count = 0; ?>
<?php foreach ($record['uploads'] as $upload): ?>
<?php if (++$count > 3) { break; } ?>
display record...
<?php endforeach ?>


Hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [benedict] Show first 3 images only in upload field

By Chris - November 13, 2009 - edited: November 13, 2009

Hi Benedict,

You can use the PHP shuffle() function to randomize the order of an array: (new code in red)

<?php $count = 0; ?>
<?php shuffle($record['uploads']); ?>
<?php foreach ($record['uploads'] as $upload): ?>
<?php if (++$count > 3) { break; } ?>
display record...
<?php endforeach ?>


I hope this helps!
All the best,
Chris