• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Parent Category and Subcategory default text

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

The best Food Apple you can get.
Taking the main category follow by the sub category

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>
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock