我在wordpress插件中编写了一个简单的函数来获取文件夹(称为模板)中的内容,但在获取工作路径时遇到了问题(因此该函数总是失效)。我的问题是:是否有wordpress函数或其他东西可以根据opendir函数的工作需要为我的插件提供路径?
function get_templates(){
$path = \'[path to my plugin]/templates\';
$dir_handle = @opendir($path) or die("Cannot open the damn file $path");
while ($file = readdir($dir_handle)) {
if(substr($file,-3) == "php" )
continue;
$TheLinkedFile = $path."/".$file;
if(file_exists($TheLinkedFile)) {
echo $TheLinkedFile.\'<br>\';
} else {
echo "nothing";
}
}
closedir($dir_handle);
}