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!
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:
Hope this helps! Please let me know if you have any questions.
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
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
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)
I hope this helps!
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
Chris