WordPress php glob();不工作?

2023-12-01

我在 WordPress 中创建了一个函数,我希望获取给定目录中的所有图像,为此我使用 PHP glob 函数,由于某种原因我无法让它工作,glob() 函数是否被禁用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()给你一个网址(http://…) 。您必须使用绝对系统路径。您可以通过使用get_theme_root()函数代替。

你的函数应该是这样的:

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;
}

More Wordpress Codex 中有此函数的详细信息.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WordPress php glob();不工作? 的相关文章

随机推荐