Page 1 of 1

Random Image sets

Posted: Tue 7. Sep 2004, 13:52
by theplinth
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 :

Code: Select all

<?php
$folder_ar = array('images1', 'images2', 'images3', 'images4');
$rand = array_rand($folder_ar);
echo $folder_ar[$rand];

?>
Then used this

Code: Select all

<img src="{PHP:rand.php}/main_r3_c2.jpg" width="37" height="288">
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 :D

Posted: Tue 7. Sep 2004, 14:27
by brans
hmm I think you gotta put your script into any script in your
render folder (view the changelog for more information), only avaiblable in the latest release. Then have a look at the replacement-tags in

Code: Select all

content.func.inc.php


and create one that suites to your needs and paste the code into any file in the init folder, not the content.func.inc.php

Posted: Wed 8. Sep 2004, 05:55
by theplinth
Ok... I dont quite know what to do yet, but I'll scope it out and let you know how I go! :D

Are you sure no one has answered this question before? I've been hunting around the forum and found a few similar threads, but no answers!

Cheers,

Tim

Posted: Wed 8. Sep 2004, 12:08
by brans
I'm not 100% sure but as I'm a frequent user I would say that I'm quite sure that everyone else was looking for smth. different, ot exactly your problem!

simply look at the changelog.txt and find out what where to place your code (render and init folder) maybe this thread will guide you to the right direction on how to use replacement tags code ;-)