Show first 3 images only in upload field

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

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: [chris] Show first 3 images only in upload field

Hi Chris,

That works well - one other thing:

To make the images appear in random order, where do I put the "orderby" bit?

Cheers,

Benedict

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