How to randomize a upload display

5 posts by 3 authors in: Forums > CMS Builder
Last Post: January 5, 2010   (RSS)

Re: [drewh01] How to randomize a upload display

By Chris - January 5, 2010

Hi drewh01,

I think the simplest way to do this would be to upload all your banner ads into the same upload field in your "home_page" single record section, and use an info field for the URL to be linked to. Then, you'd simply need to shuffle the array and break after displaying the first ad:

<?php shuffle($home_pageRecord['ad_space_1']) ?>
<?php foreach ($home_pageRecord['ad_space_1'] as $upload): ?>
<?php if ($upload['isImage']): ?>
<a href="$upload['info1']"><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /></a>
<?php break ?>
<?php endif ?>
<?php endforeach ?>


I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] How to randomize a upload display

By drewh01 - January 5, 2010

you are my hero!

Re: [drewh01] How to randomize a upload display

By Codee - January 5, 2010

Chris's method would be very stable, simple and fast (less server delay).

If you wanted the banners to rotate but on a timed increment instead of page refresh you could also incorporate some of the free code from dynamicdrive.com . I've done this for several clients to show thumbnails of product listings rotating every 2 seconds across the top of the page. I've also set up an "ad center" section inside CMSB for a client that allows them to change banner ads or banner code on the fly and appear automatically in certain pages and positions. CMSB makes this fairly easy and simple to do.

Re: [equinox69] How to randomize a upload display

By drewh01 - January 5, 2010

good to know, I appreciate it. May come in handy .