【问题标题】:Having Issues on Using PHP glob() in WordPress在 WordPress 中使用 PHP glob() 时遇到问题
【发布时间】:2017-12-19 16:37:09
【问题描述】:

在 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 [Post 1Post 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没用

【问题讨论】:

    标签: php wordpress wordpress-theming


    【解决方案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>';
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      相关资源
      最近更新 更多