There is a working code (checked on pure php), everything works, images are randomly output from the directory, but I try to output it in the wordpress template - it does not output anything. Could you tell? Here is the code
$root = ''; $path = 'images/'; function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); // php 4.2+ not needed $num = array_rand($ar); return $ar[$num]; } // Obtain list of images from directory $imgList = getImagesFromDir($root . $path); $img = getRandomFromArray($imgList);
$path = '/images/';- if the script is NOT in the root of the site, specify the path to the folder relative to the root of the site - Blacknife