Random Placement from Single Editor

3 posts by 3 authors in: Forums > CMS Builder
Last Post: August 18, 2011   (RSS)

Re: [jtedescojam] Random Placement from Single Editor

By Dave - March 31, 2010

Hi jtedescojam,

How many uploads will there be? If there will be hundreds you may want to use a different method as it will use a lot of server resources to load them all each time just to display one.

But try this (untested) code:

<?php shuffle($interior_page_photosRecord['photos']); ?>
<?php foreach ($interior_page_photosRecord['photos'] as $upload): ?>
<p><img src="<?php echo $upload['thumbUrlPath'] ?>" class="image-border" /></p>
<p><?php echo $upload['info1'] ?></p>
<?php break; ?>
<?php endforeach ?>



The PHP shuffle() function randomizes an array. See: http://php.net/shuffle

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Random Placement from Single Editor

By rconring - August 18, 2011

Hey Dave ... Thanks for that! I have been trying to figure out how to display a random photo from a "featured" article's photo gallery on the home page. This did exactly what I wanted!
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987