Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Code to display random image?

Quote Reply
Code to display random image?
hi,

was just thinking about displaying a random image on the home page every time a user views the home page - random being 1 of 10 different images for example.

if I name the images 1.gif, 2.gif, 3.gif... 10.gif, can anyone tell me how to code the global so it will randomly grab one of those images and display it when the page is called?

Hmmmm... wonder if that'll work in the static pages?

thanks

regan.
Quote Reply
Re: [ryel01] Code to display random image? In reply to
Hi regan,

One of the more experinced people may be able to help you better than me, but:

Javascript will work on your static pages. You could also easily do this so it displays a different image each time you build the page also. I also *think* you can solve this via an ssi inlcude of some sort (not entirely sure on this one).

The resource section has something on random images from memory. http://www.gossamer-threads.com/...s/Detailed/1834.html


Edit: I found this, it might help:

sub rban {
# --------------------------------------------------------
my ($rando, $rand, $count);
$count = 5;

# Get a
random banner on each build
$rand = int(rand ($count + 0.5));
if ($rand eq 1) {
$rando = "<a href=\"/url 1 here\"><IMG SRC="
image 1 url here" ALT="image 1"></a>";
}
if ($rand eq 2) {
$rando = "<a href=\"/ url 2 here\"><IMG SRC="
image 2 url here" ALT="image 2"></a>";
}
if ($rand eq 3) {
$rando = "<a href=\"/ url 3 here\"><IMG SRC="
image 3 url here" ALT="image 3"></a>";
}
if ($rand eq 4) {
$rando = "<a href=\"/ url 4 here\"><IMG SRC="
image 4 url here" ALT="image 4"></a>";
}
if ($rand eq 5) {
$rando = "<a href=\"/ url 5 here\"><IMG SRC="
image 5 url here" ALT="image 5"></a>";
}
return $rando;
}


Then add <%rban%> wherever you want the banner to be displayed.

Source: http://www.gossamer-threads.com/perl/gforum/gforum.cgi?post=95731


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: May 28, 2002, 5:45 PM
Quote Reply
Re: [Ian] Code to display random image? In reply to
How about:

Code:
sub rban {
#--------------------------------------------------

my $num = [1..9];
my $rand = $num->[rand @$num];

return qq{<a href="http://"><img src="$CFG->{build_images_url}/$rand.gif"></a>};
}

Then you'd name the images 1.gif, 2.gif, 3.gif etc.

Last edited by:

Paul: May 29, 2002, 12:57 AM
Quote Reply
Random Javascript Banner In reply to
Does anyone have a global like this one to display a random Javascript banner like Amazon uses?



<script src="http://rcm.amazon.com/e/cm?t=shop4-20&p=14&o=1&l=bn1&browse=289891&mode=kitchen&lt1=_blank" type="text/JavaScript"></script>
<noscript>
<MAP NAME="boxmap"><AREA SHAPE="RECT" COORDS="37, 588, 126, 600" HREF="http://rcm.amazon.com/e/cm/privacy-policy.html?o=1" target=main><AREA COORDS="0,0,10000,10000" HREF="http://www.amazon.com/exec/obidos/redirect-home/shop4-20" target=main></MAP><img src="http://rcm-images.amazon.com/images/G/01/rcm/160x600.gif" width="160" height="600" border="0" usemap="#boxmap" alt="Shop at Amazon.com">
</noscript>



Thanks in advance!


--

Kriis