duadpnld426905 2017-04-13 00:53
浏览 52
已采纳

Wordpress自定义帖子类型显示类别的图像

I have been trying to get something to work, i have wordpress and also have a custom post type and custom taxonomies, basically i wanted it to show an image on a single post for certain categories but the rest will show a different image.

Here is my code anyone know why this is not working, all it shows is the second image.

<?php   // Get terms for post
$terms = get_the_terms( 'story_category' );
if ( $terms == "global-freebies" || $terms == "usa-freebies" || $terms == "uk-freebies" ){ ?>
<center><span class="domain"><a href="<?php echo esc_url( $post_url ); ?>" target="_blank"><img width="250" src="http://kwikfreebies.com/wp-content/uploads/2017/04/freebie_button.jpg"></a></span></center>
<?php } else { ?>
<center><span class="domain"><a href="<?php echo esc_url( $post_url ); ?>" target="_blank"><img width="250" src="http://kwikfreebies.com/wp-content/uploads/2017/04/site_button.jpg"></a></span></center>
<?php } ?>

</div>
  • 写回答

1条回答 默认 最新

  • dpowhyh70416 2017-04-13 01:28
    关注

    This will solve your issue:

    <?php $terms = get_the_terms( $post->ID, 'story_category' );
    if ( $terms[0]->slug == "global-freebies" || $terms[0]->slug == "usa-freebies" || $terms[0]->slug == "uk-freebies"  ) :?>
    <center><span class="domain"><a href="<?php echo esc_url( $post_url ); ?>" target="_blank"><img width="250" src="http://kwikfreebies.com/wp-content/uploads/2017/04/freebie_button.jpg"></a></span></center>
    <?php else : ?>
    <center><span class="domain"><a href="<?php echo esc_url( $post_url ); ?>" target="_blank"><img width="250" src="http://kwikfreebies.com/wp-content/uploads/2017/04/site_button.jpg"></a></span></center>
    <?php endif;?>
    

    Enjoy!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line