WordPress php glob();不工作吗? [英] WordPress php glob(); not working?
本文介绍了WordPress php glob();不工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在WordPress中创建了一个函数,该函数希望获取给定目录中的所有图像,为此,我正在使用PHP glob函数,由于某种原因我无法使它正常工作,因此glob()函数已禁用可以在WordPress中使用?
I have created a function in WordPress where I wish to obtain all the images within a given directory, for which I am using the PHP glob function, for some reason I cannot get this to work, is the glob() function disabled for use within WordPress?
无效的代码...
function getAccreditaionLogos(){
define('ACCREDPATH', get_stylesheet_directory_uri() . '/img/accreditations/');
$images = glob(ACCREDPATH . '*.png');
foreach($images as $key => $img):
$get_icons = '<li><img src="'.$img.'" /></li>';
echo $get_icons;
endforeach;
}
推荐答案
函数get_stylesheet_directory_uri()
为您提供了一个Web网址(http://…)
.您必须使用绝对系统路径.您可以使用get_theme_root()
函数代替它.
The function get_stylesheet_directory_uri()
gives you a web url ( http://… )
. You have to use an absolute system path. You can get it by using the get_theme_root()
function instead.
您的函数应如下所示:
function getAccreditaionLogos(){
define('ACCREDPATH', get_theme_root() . '/img/accreditations/');
$images = glob(ACCREDPATH . '*.png');
foreach($images as $key => $img):
$get_icons = '<li><img src="'.$img.'" /></li>';
echo $get_icons;
endforeach;
}
这篇关于WordPress php glob();不工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文