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