2012-08-09 101 views
0

是否有可能根據類別ID來顯示特定文章縮略圖,這樣的事情:根據WordPress中的類別顯示發佈的縮略圖?

<?php if (has_post_thumbnail()) { 

     if (cat = 2) { 
     echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />'; 
     } elseif(cat = 3) { 
     echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />'; 
     } else { 
     echo '<img src="default.jpg" width="" height="" class="default" />' 
     } 

?> 
+0

這是鱈魚e [The Loop](http://codex.wordpress.org/The_Loop)? – 2012-08-09 15:23:04

+0

是在循環內 – styler 2012-08-09 15:34:07

回答

2

你可能要考慮的類別模板:http://codex.wordpress.org/Category_Templates

的快速解決方案會是這樣的這樣的:

if (is_category('1')) { 
    echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />'; 
} else if (is_category('2')) { 
    echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />'; 
} else { 
    echo '<img src="default.jpg" width="" height="" class="default" />'; 
} 

//you can also do this by name 
if (is_category('Category A')) { 
    echo '<img src="image1.jpg" width="" height="" class="live-holder-img" />'; 
} else if (is_category('Category B')) { 
    echo '<img src="image2.jpg" width="" height="" class="live-holder-img" />'; 
} else { 
    echo '<img src="default.jpg" width="" height="" class="default" />'; 
} 

is_category功能參考:http://codex.wordpress.org/Function_Reference/is_category