2012-05-19 32 views
0

這裏是我指的是代碼:輸出html而不是圖片的代碼?

<?php if (is_archive()) { echo '<img src="'.bloginfo('template_url').'/images/test.png" />'; }?> 

這是什麼代碼輸出:http://site.com/wp-content/themes/themename

我想它想輸出的代碼的實際圖像。我忽略了什麼部分?

+0

你能更具體。當前代碼將輸出'' – Niranjan

+0

您編寫的代碼不會輸出您所說的代碼。它要麼輸出一個圖像標籤或什麼也不要 – jprofitt

+0

這很奇怪。在我的屏幕上,它正在顯示我在那裏放置的內容。我想在代碼中可能有錯誤,但我似乎無法找到一個。 – John

回答

1

bloginfo()不輸出字符串。它直接回顯輸出流。 所以,代碼應該是:

<?php if (is_archive()) { ?> 
    <img src="<?php bloginfo('template_url'); ?>/images/test.png" />'; 
<?php } ?> 

否則,您可以使用get_bloginfo()

<?php if (is_archive()) { echo '<img src="'.get_bloginfo('template_url').'/images/test.png" />'; }?> 
+0

美麗,謝謝!我會在3分鐘內接受你的回答。 – John

0

你有沒有嘗試過這樣的:

$template_url = get_bloginfo('template_url'); 

<?php if (is_archive()) { echo '<img src="'.$template_url.'/images/test.png" />'; } ?> 
+0

你不能使用它。如果你想將bloginfo的值存儲到變量中,你應該使用'get_bloginfo()'而不是'bloginfo()' – Niranjan

+0

更多的信息在這裏:http://codex.wordpress.org/Function_Reference/get_bloginfo – Adriaan

+0

我已經給出答案。無需將其編輯爲正確的代碼。 – Niranjan

相關問題