i'm building a wordpress theme and i'm trying to get the all the jpg files from a directory in random order using php.... im using Xampp on win7 (localhost).
this is the code:
<?
$dir = get_template_directory_uri().'/images/top/';
$file_display = array ('jpg', 'jpeg');
if(file_exists($dir) == false){
echo 'Directory \'', $dir, '\' not found';
} else {
$dir_contents = scandir($dir);
shuffle($dir_contents);
foreach ($dir_contents as $file) {
$file_type = strtolower(end(explode('.', $file)));
if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true){
echo '<img src="', $dir, '/', $file, '" alt="', $file, '" />';
}
}
}
?>
i always get
Directory 'http://localhost/ni/wp-content/themes/A/images/top/' not found
i also tried to change
$dir = get_template_directory_uri().'/images/top/';
to:
$dir = "C:\xampp\htdocs\Ni\wp-content\themes\A\images\top\";
but still no luck, any help would be appreciated!
ifin front in front of the(file_exists($dir) == false)test?get_template_directory_uribyget_template_directory, because theget_template_directory_urigives an URI (and you don't want that)file_existsaccepts HTTP (amongst a few other protocols) so it shouldn't matter so long as OP is using PHP5.