Last active
August 29, 2015 14:20
-
-
Save rbk/d4c2db870fd404546331 to your computer and use it in GitHub Desktop.
Get category list magento
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Credit: http://excellencemagentoblog.com/blog/2011/09/14/magento-generate-category-tree-recursively/ | |
$rootcatId= Mage::app()->getStore()->getRootCategoryId(); | |
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId); | |
function get_categories($categories) { | |
$array= '<ul>'; | |
foreach($categories as $category) { | |
$cat = Mage::getModel('catalog/category')->load($category->getId()); | |
$count = $cat->getProductCount(); | |
$array .= '<li>'. | |
'<a href="' . Mage::getUrl($cat->getUrlPath()). '">' . | |
$category->getName() . "(".$count.")</a>\n"; | |
if($category->hasChildren()) { | |
$children = Mage::getModel('catalog/category')->getCategories($category->getId()); | |
$array .= get_categories($children); | |
} | |
$array .= '</li>'; | |
} | |
return $array . '</ul>'; | |
} | |
echo get_categories($categories); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment