WordPress php glob(); not working?

后端 未结 1 655
清歌不尽
清歌不尽 2021-01-03 11:58

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 g

1条回答
  •  北荒
    北荒 (楼主)
    2021-01-03 12:15

    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.

    Your function should look like this:

    function getAccreditaionLogos(){
    
        define('ACCREDPATH', get_theme_root() . '/img/accreditations/');
    
        $images = glob(ACCREDPATH . '*.png');
        foreach($images as $key => $img):
            $get_icons = '
  • '; echo $get_icons; endforeach; }

    More details of this function in the Wordpress Codex.

    0 讨论(0)
提交回复
热议问题