在我的Wordpress网站上,我用header.php编写了这段代码,只有在特定的帖子(产品)页面上,才能在标题下编写html。
<?php
$post = get_post();
if ( $post->ID == 'postid' ){
echo '<div>
<p>'text'
</p>
</div>
</div>
</div>';
}
?>我想在一个特定的类别页面中做同样的事情,做这样的事情
<?php
$postcat = get_the_category();
if ( $postcat->ID == 'categoryid'){{
echo '<div>
<p>'text'
</p>
</div>
</div>
</div>';
}
?>但是它不起作用,我也尝试过不同的方法,比如
<?php if (is_category('categoryname')) : ?>
<div></div>
?php endif;?>我该怎么做?
谢谢。
发布于 2021-04-23 14:16:46
您可以使用is_product_category。检查下面的代码。
<?php
if ( is_product_category( 'your-category-slug' ) ){
echo '<div>
<p>'text'</p>
</div>
</div>
</div>';
}
?>有用LINKE
发布于 2021-04-23 14:17:07
如果post =特定ID
<?php
$post = get_post();
if ( $post->ID === 'postid' ){
echo "<div>";
echo $post->post_content;
echo "</div>";
}
?>是post有“超级猫”类
<?php
$post = get_post();
if ( has_category('supercat', $post->ID)){
echo "<div>";
echo $post->post_content;
echo "</div>";
}
?>关于产品,请查看Bhautik的答案
https://stackoverflow.com/questions/67231353
复制相似问题