2011-04-29 24 views
1

嗨, 這工作得很好:php directoryIterator - 基於季節的路徑?

$dir = new DirectoryIterator(get_template_directory().'/images/headers/'); 

但是我沒有隻/頭,但我有一個/頭/夏季和頁眉/冬季目錄,我根據當前季節想用作路徑。

$summer = array(3,4,5,6,7,8,9); 

$path = null; 

if (in_array(date('n'), $summer)) { 
    $path = get_template_directory().'/images/headers/summer/'; 
} else { 
    $path = get_template_directory().'/images/headers/winter/'; 
} 

$dir = new DirectoryIterator($path); 

這是什麼問題?如果我使用這個,我的頁面是空白的!

+1

'get_template_directory()'是一個wordpress特定的函數,不應該爲代碼重要 - 只是返回到目錄的絕對路徑。 – matt 2011-04-29 09:11:13

回答

2

我認爲有3個possibilits ..

  1. 在$路徑不存在,請與 if(!is_dir($path)) die('no dir there');

  2. 你的函數get_template_directory 拋出一個致命

  3. 您使用PHP4其中 DirectoryIterator不存在

1

我認爲這應該應該很好,我不知道爲什麼你會得到一個白色的屏幕。這通常發生在您收到致命錯誤並且您的error_reporting設置不正確時。

請設置您的error_reporting爲E_ALL:

error_reporting(E_ALL); 
ini_set('display_errors', true); 

這應該顯示出現的任何錯誤。

0

它看起來像你沒有啓用錯誤報告。在您的腳本中執行error_reporting(E_ALL)或查找apache日誌中的錯誤。

你以後可能會得到一個錯誤頁面上,因爲你承擔不同的事情有關的內容或在目錄(從http://www.php.net/manual/en/directoryiterator.construct.php)錯誤的權利(也許空目錄):約

Throws an UnexpectedValueException if the path cannot be opened. 

但是,如果沒有細節錯誤,這只是猜測。