Products
GG网络技术分享 2025-03-18 16:12 13
Using pure PHP code inside WordPress I am having trouble on getting the glob()
work to generate image source.
<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>
As you can see I tried to hardcoded the $directory
as \"http://geocaa.com/wp-content/themes/Booting/img/services/\";
and also I already investigate on these two Post [Post 1 & Post 2 ] regarding the same issues but the solutions there still not working for me!
The get_theme_root()
retuns nothing but the get_template_directory()
is returning something which is more like
$images = glob(get_template_directory().$directory . \"*.png\");
/home/vcbb/public_html/wp-content/themes/geocaa/img/services/img.png
and useless for image src
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议在WordPress中使用纯PHP代码我无法获得 glob()</ code>工作 生成图像源。</ p>
&lt; div class =“carousel-inner”role =“listbox”style =“height = 600px; width = 1000px;”&gt; &lt;?php
$ directory =“http://geocaa.com/wp-content/themes/Booting/img/services/\";
$ images = glob($ directory。”* .png“); \\ n foreach($ images as $ image)
{
echo\'&lt; div class =“dynamic item”&gt;\';
echo\'&lt; img src =“\'。$ image。\'”alt =“。 ..“&gt;\';
echo\'&lt; / div&gt;\';
}
?&gt;
&lt; / div&gt;
</ code> </ pre>
As 你可以看到我试图将 $ directory </ code>硬编码为“http://geocaa.com/wp-content/themes/Booting/img/services/”; </ code>以及 我已经调查了这两篇文章 [Post 1 &amp; Post 2 ]关于相同的问题,但那里的解决方案仍然无效 对我来说!</ p>
get_theme_root()</ code>只返回 get_template_directory()</ code>返回更像是</ p>的内容
$ images = glob(get_template_directory()。$ directory。“* .png”); </ code> </ pre>
/home/vcbb/public_html/wp-content/themes/geocaa/img/services/img.png </ p>
</ blockquote>
对图像src无用</ p> \\ n </ div>
网友观点:
Try this:
$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>\';
}
Demand feedback