最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

categories - Parent Category and Subcategory default text generated with category

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论