admin管理员组文章数量:1405736
I need help on something I am unable to do on my website.
I have several category and sub category on my page. For E.g
Food
-Apple
-Orange
Shirt
Laptop
-HP
-Dell
I would like on each category page and sub category page a default text appearing as so:
For sub category
The best Food Apple you can get.
For the main category
The best Food you can get
This should be the same for all category and subcategory page.
I am using the below code for the moment but the main category is still displaying the subcategory e.g FoodApple
<h2 class="supply">The best
<?php
$terms = get_the_terms( get_the_ID(), 'product_cat' );
foreach ( $terms as $term ){
if ( $term->parent == 0 ) {
echo $term->name ;
}
}
foreach ( $terms as $term ){
if ( $term->parent == !0 ) {
echo $term->name ;
}
}
?>
you can get </h2>
I would be so grateful if someone can help.
Thanks
本文标签: categoriesParent Category and Subcategory default text generated with category
版权声明:本文标题:categories - Parent Category and Subcategory default text generated with category 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744902730a2631439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论