2017-04-13 147 views
0

我一直在努力获得的东西上班,我有wordpress,也有一个自定义帖子类型和自定义分类法,基本上我希望它显示在某个类别的单个帖子上的图像但其余的将显示不同的图像。WordPress的自定义文章类型显示图像为类别

这里是我的代码有人知道为什么这不起作用,它显示的是第二个图像。

<?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 } ?>

+0

您是否试图回应$条款?你的输出是什么? – cosmoonot

+0

如果我使用生态我似乎无法得到后URL可以正常工作,所以我不得不打破的PHP,所以我可以使用html – Brian

+0

基本上我运行一个免费的网站,我也有提示在那里以及所有的免费赠品类别我想要一个按钮,说得到这个免费赠品,并在所有其他我想要访问网站按钮 – Brian

回答

1

这将解决您的问题:

<?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;?> 

享受!

+0

显示死网页 – Brian

+0

更新:条件缺少密钥,请再试一次 – ScyGeek

+0

非常感谢所有帮助,页面现在可以正常工作,但由于某种原因没有从定制分类法中读取 – Brian

相关问题