Random picture display

2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 21, 2008   (RSS)

Re: [chassa2556] Random picture display

By Dave - June 21, 2008

Hi Charles.

Did you figure this out already? When I reload the main page it seems like the image changes already?

If not, you can display just one image by adding a <?php break; ?> tag at the end of the image foreach loop like this. (Note my variable is called $newsRecord, yours might be named something else).

<?php foreach ($newsRecord['uploads'] as $upload): ?>
... display image here ...
<?php break; ?>
<?php endforeach ?>


Break means "break out of the loop" and only show one.

Next, you can shuffle the order of the uploads so the first one displayed will always be random. Just add this tag _before_ the foreach tag:

<?php shuffle($newsRecord['uploads']); ?>
<?php foreach ($newsRecord['uploads'] as $upload): ?>
...


Hope that helps! Let me know if you have any more questions about that.
Dave Edis - Senior Developer
interactivetools.com