2016-07-07 83 views
1

我開始學習Wordpress我正在製作自己的主題。在設計中,我有一些應該顯示出來的圖像...但是它們沒有。Wordpress圖像不顯示

我用這個代碼:

<div class="col-xs-4"> 
    <a href="#"><img src="images/html_brand.jpg" class="img-responsive"></a> 
</div> 

,然後我發現我應該使用PHP鏈接到我的形象:

<div class="col-xs-4"> 
    <a href="#"> 
     <img src="<?php bloginfo('stylesheet_directory'); ?>html_brand.jpg" 
        class="img-responsive"> 
    </a> 
</div> 

但問題是,圖像仍然沒有按」 t顯示。是的,我沒有上傳到我的網絡服務器。我有他們在我的主題的目錄:mythemename/images/html_brand.jpg

+0

+0

那不是有效的,使用:'/images/html_brand.jpg' –

+0

如果不行的話就用這個

回答

0

如果使用bloginfo()輸出你的主題路徑,需要通過其餘的路徑添加其他/,跟着你的形象。根據您放置你的形象,這應該工作:

<img src="<?php bloginfo('stylesheet_directory'); ?>/images/html_brand.jpg" class="img-responsive"> 

然而,bloginfo()最終依靠get_template_directory_uri()工作,所以你可能也只是使用:

<img src="<?php echo get_template_directory_uri(); ?>/images/html_brand.jpg" class="img-responsive"> 

小幅回調:

bloginfo()stylesheet_directory具體論據實際上可以依靠get_stylesheet_directory_uri()到功能 - get_template_directory_uri()就像我最初所說的那樣。

https://core.trac.wordpress.org/browser/tags/3.4.2/wp-includes/general-template.php#L439