sicario
Member
- Oct 21, 2018
- 36
- 11
- 8
Hello all,
Would be grateful if someone can help me with the below.
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
If there is no subcategory only outputting the main category
This should be the same for all category and subcategory page.
I am using the below code but is able to output only the main category
Would be grateful if someone can help me with the below.
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
Taking the main category follow by the sub categoryThe best Food Apple you can get.
If there is no subcategory only outputting the main category
The best Shirt you can get
This should be the same for all category and subcategory page.
I am using the below code but is able to output only the main category
Code:
<h2 class="supply">The best
<?php
$cat = get_the_terms( $product->ID, 'product_cat' );
foreach ($cat as $categoria) {
if($categoria->parent == 0){
echo $categoria->name;
?>
you can get </h2>