繁体   English   中英

根据Wordpress中的类别显示缩略图?

[英]displaying a post thumbnail depending on category in Wordpress?

是否可以根据类别ID显示特定的后缩略图图像,如下所示:

<?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" />'
      }

 ?>

您可能需要查看类别模板: 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM