您好,我已经编写了从WordPress中的文件夹中获取图像的代码,但路径似乎不起作用。这是我的代码。在我的主题文件夹中有图像,然后是empl文件夹,但它给出错误信息“无法打开目录:没有这样的文件或目录在”,我甚至尝试服务器文件根目录的php,但它不起作用。我的文件位于page-template目录中。
$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++;
}发布于 2013-09-04 14:31:32
我找到了解决方案:
$filePath=get_template_directory().'/images/empl';发布于 2013-09-02 21:02:43
您必须使用get_bloginfo()而不是bloginfo(),如下所示:
$filePath=get_bloginfo('template_url').'/images/empl';为什么?来自the codex
bloginfo()总是将结果打印到浏览器。如果需要在
中使用这些值,请使用get_bloginfo(). PHP
https://stackoverflow.com/questions/18573187
复制相似问题