Magento - display only the "root category" in the top menu

I try to display the product menu item in my top menu, and then all subcategories are displayed below it in the drop-down menu.

I am looking at the code in the top.phtml file and I just can't figure out how to configure it to display the root category with all the categories below it.

This is the current code that pulls out categories and subcategories:

<?php foreach ($this->getStoreCategories() as $_category): ?> <?php echo $this->drawItem($_category) ?> <?php endforeach ?> 

Does anyone have an idea of ​​how I can only display the root category as a menu item (for example, "Products") and then display all the subcategories (and their subcategories) below it?

Thanks.

+6
source share
1 answer

This is a fairly common question, and it probably already exists. This should start:

  <?php $root_category = Mage::getModel('catalog/category')->load(3); // Put your root category ID here. $subcategories = $root_category->getChildren(); foreach(explode(',',$subcategories) as $subcategory) { $category = Mage::getModel('catalog/category')->load($subcategory); echo '<a href="'.$category->getURL() .'" />'.$category->getName().'</a><br/>'; } ?> 
+5
source

Source: https://habr.com/ru/post/908231/


All Articles