Random Image sets
Posted: Tue 7. Sep 2004, 13:52
Hi,
I have what appears to be a simple question, yet could be complex, I dont know!
I have site which i have created a few different image sets for. That is, its the same site, but the subtle image in the background, which is sliced in to several images, is different. Just to make it a little more interesting.
I want the visitor to get a random image set for every page they go to.
To show you what I mean, here is the folder structure
/images1/main_pic1
/images1/main_pic2
/images1/main_pic2
/images2/main_pic1
/images2/main_pic2
/images2/main_pic3
/images3/main_pic1
/images3/main_pic2
/images3/main_pic3
You get the picture! I cannot just use the RAN function cause obviously I want a random DIRECTORY to be chosen, not a random image.
I wrote a small script :
Then used this
In my template. HOWEVER, because the script was called many times, I got a jumble of pictures from each different set!
I would really appreciate a solution to this question or at least to be pointed in the right direction. I can code PHP, but I'm just not sure how to impliment it in to PHPWCMS yet.
Cheers
I have what appears to be a simple question, yet could be complex, I dont know!
I have site which i have created a few different image sets for. That is, its the same site, but the subtle image in the background, which is sliced in to several images, is different. Just to make it a little more interesting.
I want the visitor to get a random image set for every page they go to.
To show you what I mean, here is the folder structure
/images1/main_pic1
/images1/main_pic2
/images1/main_pic2
/images2/main_pic1
/images2/main_pic2
/images2/main_pic3
/images3/main_pic1
/images3/main_pic2
/images3/main_pic3
You get the picture! I cannot just use the RAN function cause obviously I want a random DIRECTORY to be chosen, not a random image.
I wrote a small script :
Code: Select all
<?php
$folder_ar = array('images1', 'images2', 'images3', 'images4');
$rand = array_rand($folder_ar);
echo $folder_ar[$rand];
?>
Code: Select all
<img src="{PHP:rand.php}/main_r3_c2.jpg" width="37" height="288">
I would really appreciate a solution to this question or at least to be pointed in the right direction. I can code PHP, but I'm just not sure how to impliment it in to PHPWCMS yet.
Cheers