Random picture display
2 posts by 2 authors in: Forums > CMS Builder
Last Post: June 21, 2008 (RSS)
By chassa2556 - June 20, 2008
Hi I would like to randomly display pictures on this index page. http://www.straloch.com/ I have an index page section with a gallery loaded. Is there a way that each time the page refreshes it calls in a new image? Many thanks in advance
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).
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:
Hope that helps! Let me know if you have any more questions about that.
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
interactivetools.com