Products
GG网络技术分享 2025-03-18 16:12 0
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>
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我一直试图让某些东西起作用,我有wordpress,还有自定义的帖子类型和自定义分类法, 基本上我想让它在某个帖子上显示特定类别的图像,但其余的将显示不同的图像。</ p>
这是我的代码,任何人都知道为什么这不起作用,所有它显示 是第二个图像。</ p>
</ p>
&lt;?php / /获取发布条款 $ terms = get_the_terms(\'story_category\');
if($ terms ==“global-freebies”|| $ terms ==“usa-freebies”|| $ terms == “uk-freebies”){?&gt;
&lt; center&gt;&lt; span class =“domain”&gt;&lt; a href =“&lt;?php echo esc_url($ post_url);?&gt;” target =“_ blank”&gt;&lt; img width =“250”src =“http://kwikfreebies.com/wp-content/uploads/2017/04/freebie_button.jpg”&gt;&lt; / a&gt;&lt; / span&gt;&lt; / center&gt;
&lt;?php} else {?&gt;
&lt; center&gt;&lt; span class =“domain”&gt;&lt; a href =“&lt;?php echo esc_url( $ post_url);?&gt;“ target =“_ blank”&gt;&lt; img width =“250”src =“http://kwikfreebies.com/wp-content/uploads/2017/04/site_button.jpg”&gt;&lt; / a&gt;&lt; / span&gt;&lt; / center&gt;
&lt;?php}?&gt; </ code> </ pre>
</ div>
</ div>
</ DIV>
网友观点:
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!
Demand feedback