2013-10-10 4 views
1

WordPress에서 특정 디렉토리 내의 모든 이미지를 얻으려는 함수를 만들었습니다. PHP glob 함수를 사용하고 있는데 어떤 이유에서이 함수를 사용할 수 없는데 glob() 함수는 다음과 같이 비활성화되어 있습니다. WordPress 내에서 사용 하시겠습니까?WordPress php glob(); 작동 안함?

작동하지 않는 코드 ...

기능 get_stylesheet_directory_uri() 당신에게 웹 URL을 제공
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; 
} 
+1

'var_dump (get_stylesheet_directory_uri()) '가 보여주는 것은 모든 할당 후에'ACCREDPATH'에 무엇이 있습니까? –

+0

좋은 지적, 잘못된 선언을 사용하고 있습니다. – iamgraeme

답변

4

(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.