在WordPress中使用纯PHP代码我无法让glob()
工作来生成图像源。
<div class="carousel-inner" role="listbox" style="height=600px; width=1000px;">
<?php
$directory = "http://geocaa.com/wp-content/themes/Booting/img/services/";
$images = glob($directory . "*.png");
foreach($images as $image)
{
echo '<div class="dynamic item">';
echo ' <img src="'.$image.'" alt="...">';
echo ' </div>';
}
?>
</div>
正如您所见,我尝试将$directory
硬编码为"http://geocaa.com/wp-content/themes/Booting/img/services/";
,并且我已经调查过这两篇帖子 [Post 1&amp; Post 2]关于相同的问题,但那里的解决方案仍然无效!
get_theme_root()
只返回get_template_directory()
返回更像是
$images = glob(get_template_directory().$directory . "*.png");
/home/vcbb/public_html/wp-content/themes/geocaa/img/services/img.png
对图像src无用
答案 0 :(得分:1)
试试这个:
$directory = "/img/services/";
$images = glob(get_template_directory().$directory . "*.png");
foreach($images as $image)
{
echo '<div class="dynamic item">';
echo ' <img src="'. str_replace(get_home_path(), get_home_url(), $image) .'" alt="...">';
echo ' </div>';
}