This script will randomize images. Useful for ads or simply a change of scenery. Link capabilities are in this script. Please comment back, I would like to hear everyone’s response.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | <?php // Created by Matt Lo, very simple :) class random_images { // store images protected $_images = array(); // no constructor needed // properties per image, protected, all parameters are strings // $location = path/to/image.jpg, REQUIRED public function define_image($location, $title=NULL, $link=NULL, $target='_blank') { // html code for image with variables // removing border, you can edit it out or leave it in $image = '<img src="'.$location.'" alt="'.$title.'" style="border: none;" />'; // if link param has value to it... if($link != '') { $image = '<a href="'.$link.'" target="'.$target.'">'.$image.'</a>'; } // array, key index starts at 0 $this->_images[] = $image; } public function display() { // randomize the array by finding max $rand_int = mt_rand(0, count($this->_images)-1); return $this->_images[$rand_int]; } } // Usage // NOTE: You can put the class into a separate page, then include it // start $image = new random_images(); // example 1 $image->define_image("http://cdn.joomla.org/images/logo.png", 'testing j'); // lets add a mix of linked images $image->define_image("http://drupal.org/sites/all/themes/bluebeach/logos/drupal.org.png", 'drupal', 'http://drupal.org'); // output echo $image->display(); ?> |