Created
June 18, 2013 16:00
-
-
Save dannevang/5806597 to your computer and use it in GitHub Desktop.
Magento. Get categories by ID and display subcategories if any. Will work directly from top.phtml
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 $_helper = Mage::helper('catalog/category'); | |
$children = Mage::getModel('catalog/category')->getCategories(CATETGORY_ID_HERE); | |
foreach ($children as $category): | |
$category = Mage::getModel('catalog/category')->load($category->getId()); | |
echo '<li class="level1"><a href="' . $category->getUrl() . '">' . $category->getName() . '</a>'; | |
$category = Mage::getModel('catalog/category')->load($category->getId()); | |
$_subcategories = $category->getChildrenCategories(); | |
if (count($_subcategories) > 0): ?> | |
<ul> | |
<?php foreach($_subcategories as $_subcategory): ?> | |
<li class="level2"> | |
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> | |
<?php echo $_subcategory->getName() ?> | |
</a> | |
</li> | |
<?php endforeach; ?> | |
</ul> | |
<?php endif; | |
echo '</li>'; | |
endforeach; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment