【问题标题】:WordPress php glob(); not working?WordPress php glob();不工作?
【发布时间】:2013-10-10 11:59:31
【问题描述】:

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

【问题讨论】:

  • 什么显示var_dump(get_stylesheet_directory_uri()),什么是ACCREDPATH 在所有分配之后?
  • 好点,我使用了错误的声明。

标签: php wordpress glob


【解决方案1】:

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

更多details of this function in the Wordpress Codex.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 2015-02-05
    相关资源
    最近更新 更多