Image Rotation Script

Written by: burt
Date: February 9, 2008
Filed under: Uncategorized
Trackback · Comment

A while back I wanted to show some images on this blog - but have the ability to randomly select an image to show. I wanted it to be as "hands off" as possible, so here's the code I came up with;

$idea_images = glob("ideasfestival*.gif");
shuffle($idea_images);
echo '<a xhref="http://www.ideasfestival.org"><img border="0" xsrc="http://www.osworld.biz/', $idea_images[0], '" /></a>';

Basically, this code puts all the images that start with "ideasfestival" into an array. It then shuffles the array and outputs the first image selected.

If you want to use this code, you'll need to change it a bit, here's how;

    1. Change the link url - simply change the http://www.ideasfestival.org to your own URL link
    2. Change the first "glob" line from ideasfestival to aaa (or somesuch)
    3. Make sure that all your images that you want to rotate start with "aaa" (or whatever you changed the previous step to).

This is a nice easy, hands off way to make an image "rotator" - when you want to add more images, simply make sure that their name starts with "aaa" and upload it. Easy as 123.

Have fun!

Comments

  1. Comment by burt — February 9, 2008 @ 10:13 am

    ps, I have no idea why Wordpress is so crap at pasting code!

    Make sure to change xsrc to src and xhref to href if you do use the block of code.

  2. Comment by Sea Monsters — February 11, 2008 @ 7:02 pm

    This script could come in handy. Could use it to rotate some banners around..

  3. Comment by burt — February 18, 2008 @ 6:24 pm

    Yep, you could do that.

Leave a comment



Did you enjoy reading this?
Please consider subscribing to our RSS Feed!


Subscribe by Email
Get notified by email every time we update this Blog!


 

Subscribe (RSS)

Recent Comments

Sponsored By

What Others Are Saying