尝试使用has_term(). 类似这样:
<?php if( has_term(\'term1\', \'taxonomy_name\', $post) ) { ?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php }elseif ( has_term( \'term2\', \'taxonomy_name\', $post) ) { ?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php } else { ?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php } ?>
您可能还想尝试使用速记if/else语句,这会使代码更干净,在类似这样的情况下更容易阅读。
使用速记的相同示例:
<?php if( has_term(\'term1\', \'taxonomy_name\', $post) ): ?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php elseif ( has_term( \'term2\', \'taxonomy_name\', $post) ) :?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php else: ?>
<img src="http://www.site.com/wp-content/themes/site/img/stars-01.png" width="100" height="21" alt="default">
<?php endif; ?>
希望这有帮助!