Log in

View Full Version : Dynamically randomly populated categorized images in sidebar



arjenjonge
03-08-2011, 02:56 PM
Hey guys,

After a long search on several scripting websites I eventually found this forum. I've been trying to find a script that does the following:

- Display random images on page refresh
- Retrieve the random images automatically from a folder
- The images have to be divided in categories

For example, I want 6 images vertically aligned in my sidebar on my website. 6 different categories. And each time a user refreshes the page, all 6 images have to be replaced by another image from 1 of those 6 categorized folders.

I've been looking in the Swiss Army script, written by jscheuer1, which works amazing, but the code is way too complex for my beginner skills. It basically does exactly what I want the script to do on my website, but I don't know if can be customized the way I want it, displaying 6 images from 6 locations and cycle when being refreshed. Can anyone give me some tips on how I can achieve this?

ps. I'm sorry about the 'descriptive' title.

Beverleyh
03-08-2011, 03:33 PM
If you can use php on your server you could try this script here: http://www.marcofolio.net/webdesign/php_random_image_rotation.html

Just upload a copy of the default "rotate.php" file from the download pack into each category image folder (folders 1 to 6) and then add this HTML to your web page;

<img src="path/to/folder1/rotate.php" height="150" width="150" alt=""/><br/>
<img src="path/to/folder2/rotate.php" height="150" width="150" alt=""/><br/>
<img src="path/to/folder3/rotate.php" height="150" width="150" alt=""/><br/>
<img src="path/to/folder4/rotate.php" height="150" width="150" alt=""/><br/>
<img src="path/to/folder5/rotate.php" height="150" width="150" alt=""/><br/>
<img src="path/to/folder6/rotate.php" height="150" width="150" alt=""/>Make sure each src="" value points to the "rotate.php" files in the different category image folders.

That should be it.

arjenjonge
03-08-2011, 03:42 PM
Wow! Thanks for the quick and helpful reply! This is exactly what I needed!

Beverleyh
03-08-2011, 04:04 PM
no problem - and welcome to DD!

arjenjonge
03-09-2011, 09:41 AM
And I'm back. The PHP script doesn't seem to be working properly. I created the six folders, inserted the images and the rotate.php script in each folder, and inserted the HTML code on my main page, linking to the correct folders.

The PHP scripts seems to be loading one of the images, but isn't rotating when refreshing the page. And when I changed the images, it kept displaying the (already deleted) old image for a while. Are the images cached when loading? This would explain why the image isn't refreshing instantly after deleting it on my server (and localhost, for testing purposes).

I've tested the script in Chrome, Firefox 4 Beta, and Safari. They all give the same result.

Link to my testing page: http://www.arjendejonge.nl/msv/sidebar/index.php

Beverleyh
03-09-2011, 10:44 AM
Probably a cache issue - there is some talk of it in the comments on that webpage from my first reply.

Try adding this line after the initial opening <?php tag in each "rotate.php" script;

header("Cache-Control: no-cache, must-revalidate");

The default script is working fine for me though: http://jemthingsandstuff.co.uk/testing/rotate_test/page.php

arjenjonge
03-09-2011, 01:50 PM
Adding the Cache-Control didn't help on my server. Strangely enough, it kinda works on my localhost. It definitely randomises the images, but in the same order. All the images are the same in all six folders, and all six images are the same when refreshed. This won't be a problem in the final version of the script ofcourse, since I won't be using duplicate images.

arjenjonge
03-09-2011, 01:53 PM
Okay, bad news. PHP isnt supported on the webpage I'm supposed to edit. They wasted my time hahah. Ah well, another learning experience.


Thanks for the help, and at least I know where I need to be when I need a script or help etc.