-
☆ A M B ☆
- 24,524 Posts
Do you want it to be a random image taken from a given folder of images? If so, I use this
<?php
// get images from bg image directory
if ($handle = opendir('./assets/images/top')) {
$i = 1;
while (false !== ($file = readdir($handle))) {
if (substr($file, 0, 1) != ".") {
$images[$i] = $file;
$i++;
}
}
closedir($handle);
}
//return a random filename
$randomimage = rand(1, count($images));
return $images[$randomimage];
?>
And use it like this in my template as a background image:
<style type="text/css">
#topblock {
background: #7d96bc url(assets/images/top/[!RandomImage!]) center no-repeat;
}
</style>
}
-
☆ A M B ☆
- 24,524 Posts
Or ask, and somebody else will probably have something that does much the same thing for one of their sites that they’ll share
Here’s another random image snippet
http://modxcms.com/extras/package/?package=364
You also might find this interesting
http://modxcms.com/forums/index.php?topic=28480.0
Quote from: sottwell at Jul 05, 2009, 11:08 PM
//return a random filename
$randomimage = rand(1, count($images));
return $images[$randomimage];
?>
I think this might be significantly faster (though proabably not noticably so):
return (array_rand($images));
-
☆ A M B ☆
- 24,524 Posts
Never heard of that one... looks like it’s time to go back to reading docs instead of trashy romance novels!
Quote from: sottwell at Jul 06, 2009, 03:24 AM
Never heard of that one... looks like it’s time to go back to reading docs instead of trashy romance novels!
Actually, I found that in a trashy romance novel.