【问题标题】:Can't Retrieve Images With stylesheet_directory无法使用 stylesheet_directory 检索图像
【发布时间】:2023-04-06 07:52:01
【问题描述】:

我想在我正在处理的 Wordpress 主题中检索三张图片。然而,实际上并没有检索到任何图像。这是我现在的代码。我也尝试了 get_stylesheet_directory_uri() (没有帮助)。

 <div class="col-md-4"> <img class = "img-responsive center-block" src ="<?php bloginfo('stylesheet_directory'); ?>/Assets/imgs/BlogReferral" alt = "Design"> 
 </div><!-- End Col --> <div class = "col-md-4"> <img class = "img-responsive center-block" src ="<?php bloginfo('stylesheet_directory'); ?>/Assets/imgs/InstagramReferral" alt = "Code">
 </div><!-- End Col -->
   <div class = "col-md-4">
          <img class = "img-responsive center-block" src ="<?php bloginfo('stylesheet_directory'); ?>/Assets/imgs/ContactReferral" alt = "Design">
 </div><!-- End Col -->         

【问题讨论】:

    标签: php css wordpress adobe-brackets


    【解决方案1】:

    使用函数:get_template_directory_uri()函数。
    图片路径为:YOUR_THEME_FOLDER/Assets/imgs/IMAGE_NAME

     <div class="col-md-4"> <img class = "img-responsive center-block" src ="<?php echo get_template_directory_uri() ?>/Assets/imgs/BlogReferral" alt = "Design"> 
             </div><!-- End Col --> <div class = "col-md-4"> <img class = "img-responsive center-block" src ="<?php echo get_template_directory_uri(); ?>/Assets/imgs/InstagramReferral" alt = "Code">
             </div><!-- End Col -->
               <div class = "col-md-4">
                      <img class = "img-responsive center-block" src ="<?php echo get_template_directory_uri(); ?>/Assets/imgs/ContactReferral" alt = "Design">
             </div><!-- End Col -->
    

    如果您使用儿童主题。那么你需要使用函数get_stylesheet_directory_uri()

    图片路径为:YOUR_CHILD_THEME/Assets/imgs/IMAGE_NAME

    <div class="col-md-4"> <img class = "img-responsive center-block" src ="<?php echo get_stylesheet_directory_uri(); ?>/Assets/imgs/BlogReferral" alt = "Design"> 
             </div><!-- End Col --> <div class = "col-md-4"> <img class = "img-responsive center-block" src ="<?php echo get_stylesheet_directory_uri(); ?>/Assets/imgs/InstagramReferral" alt = "Code">
             </div><!-- End Col -->
               <div class = "col-md-4">
                      <img class = "img-responsive center-block" src ="<?php echo get_stylesheet_directory_uri(); ?>/Assets/imgs/ContactReferral" alt = "Design">
             </div><!-- End Col -->
    

    【讨论】:

    • 感谢您的回答!但它仍然无法检索图像!
    • 您使用的是子主题吗? @mayaroy
    • 我没有使用儿童主题@vrajesh
    • 好的,很好。为此,您需要使用 get_stylesheet_directory_uri()。 @mayaroy
    猜你喜欢
    • 2011-09-06
    • 2020-04-22
    • 2014-07-02
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多