Search code examples
phpsmartyprestashopprestashop-1.6

Prestashop - How to get a specific sub category using parent category id


I am new to PrestaShop. I am trying to get an array of sub-categories using parent category id, so I can refer to the different sub-category in different circumstances. Actually, I want to place an if statement in a foreach loop and check if its the first iteration of the loop then grab the link of 1st sub-category enlisted and if it's 2nd iteration then grab the link of 2nd sub-category and so on. Can anybody help me?

Thanks in advance! and sorry for my bad English.


Solution

  • to get first level children:

    $subcategories = Category::getChildren($id_parent, $id_lang);
    

    to loop through:

    foreach($subcategories as $category) {
      echo $category['name'];
    }