Page 1 of 1

Looking for an easy image rotator module

Posted: Sat Jul 07, 2007 10:08 pm
by lauraproc
Hi i've looked through the extensions site but can't quite find what I need.

I want a random image to load each time a page is loaded. I see there's many flash image rotators
but with each page refresh I want a random image to appear and stay on the page, until the next refresh.

Could someone please point me in the right direction?

Many thanks

Re: Looking for an easy image rotator module

Posted: Sat Jul 07, 2007 11:07 pm
by doctorj

Re: Looking for an easy image rotator module

Posted: Sun Jul 08, 2007 10:22 am
by lauraproc
That is a nice extension however I don't want the images to change whilst viewing the page.

So you click a menu link -> loads up content page with an image.
Each time you click the menu link -> new image will be loaded (randomly)

Any advice?

Re: Looking for an easy image rotator module

Posted: Sun Jul 08, 2007 4:14 pm
by doctorj
Lets try this:

In your CSS sheet create a new class (maybe rotate) and assign a script we will create later called rotate (stored in the root folder of your template). Here is what the css will look like:

Code: Select all

rotate {
   background-image: url("../rotate.php")
}


Now create the rotate script, open notepad (or any text editor) and paste then into it:

Code: Select all

<?php
// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
    foreach($exts as $ext) { // for each extension check the extension
        if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
            $files[] = $file; // it's good
            ++$i;
            }
        }
    }
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>


Save this script as rotate.php. Now load that new css class in your template. i.e. something like:

Code: Select all

<div class="rotate" align="center">YOUR_DATA</div>


And everytime they click on a new link it will chnage the photos. It does not change them all the time if sometimes clicks on the links to fast. Hence the microtime.

Good Luck!

Re: Looking for an easy image rotator module

Posted: Sun Jul 08, 2007 10:21 pm
by lauraproc
Thank you so so much for all your help! I'm quite new to this, just wanted to ask:

I've done everything but how do I insert this code into the one static content page?
YOUR_DATA


Thank you so much!
Laura

Re: Looking for an easy image rotator module

Posted: Mon Jul 09, 2007 10:56 am
by lauraproc
I don't understand how to put in coding (
YOUR_DATA
)
into a content section within joomla?

Re: Looking for an easy image rotator module

Posted: Mon Jul 09, 2007 5:07 pm
by doctorj
This is something you need to add to your template code. Preferably in the section where you want your random photo's to show. This is a script for rotating photos and not for slideshows.

And yes you can use this without adding the YOU_DATA. You just use:

Code: Select all

<div class="rotate"></div>

Re: Looking for an easy image rotator module

Posted: Fri Aug 17, 2007 3:03 pm
by scwilder
doctorj, I tried using your script and it only works sometimes. It always work when you open a new browser, but when you click on another link. It randomly changes and I'm not quite getting when it is. Where in the script is this control? The microtime?

Thanks!

Re: Looking for an easy image rotator module

Posted: Thu Sep 06, 2007 2:48 am
by doctorj
If you are using fire fox read this:

Firefox has some unique web caching features that are designed to speed up the browsing process. With scripts like this, Firefox can appear to have its share of issues.

To quote an article released on the Scot Finnie Newsletter page - he addresses this issue as follows:

There’s only one about:config-based tweak that I’m currently recommending (although I expect to add others in the near future). This recommendation really only applies to people who have fast Internet connections or those who are Webmasters, news junkies, possibly online gaming, anything where it’s mandatory that clicking the Refresh button always shows you the very latest information on that Web page. If that describes the way you need or want to work, you can configure Firefox to work the same way Internet Explorer’s check for website updates on “Every visit to the page.”

To make this change, find this entry in about:config:

browser.cache.check_doc_frequency

The default setting is represented by the numeral 3, and corresponds to “when appropriate/automatically.” To change it, simply double-click the browser.cache.check_doc_frequency entry. A small dialog box will open. Type the numeral 1 to change it to “Each Time” and press OK. Here’s a description of the available options for this particular setting:

0 = Once per session
1 = Each time
2 = Never
3 = When appropriate/automatically

----Option 2 ------

The following is a workaround for the Firefox caching problem. Images are reloaded with every click (up to 100 different images). In the code shown below simply replace the [] brackets with tags

Two steps to firefox heaven:
1. insert this somewhere above where the rotation script is called:
[?PHP srand((double)microtime()*1000000); ?]
2. change the url of your rotate.php to this:
rotate.php?image=[?PHP echo rand(0,100); ?]

If you really need more than 100 randomised images change the 100 figure.