Hi I have written code for taking images from a folder in WordPress but the path doesn't seem to be working. Here is my code. In my theme folder there is images and then empl folder but it gives error message "failed to open dir: No such file or directory in", I even tried server document root of php but it is not working. My file resides in page-template directory.
$string =array();
$filePath=bloginfo('template_url').'/images/empl';
echo $filePath;
$dir = opendir($filePath);
echo $dir;
while ($file = readdir($dir)) {
if (preg_match("/.png/",$file) || preg_match("/.jpg/",$file) || preg_match("/.gif/",$file) ) {
$string[] = $file;
}
}
$i=0;
while (sizeof($string) != 0 ){
echo $i;
$img = array_pop($string);
echo "<div class='employee'><img src='$filePath$img' data-src='$filePath$img'></div>";
if($i>24)break;
$i++;
}
you have to use
get_bloginfo()
instead ofbloginfo()
, like this:Why? From the codex: