Skip to content

Instantly share code, notes, and snippets.

@zeljkoprsa
Created February 18, 2011 12:42
Show Gist options
  • Save zeljkoprsa/833616 to your computer and use it in GitHub Desktop.
Save zeljkoprsa/833616 to your computer and use it in GitHub Desktop.
Magento Category tree navigation
<?php
$categories = Mage::getModel('catalog/category')->load(1)->getChildren();
$categoryIDs = explode(',',$categories);
?>
<ul>
<?php foreach($categoryIDs as $categoryID): ?>
<li>
<?php $category = Mage::getModel('catalog/category')->load($categoryID);?>
<a href="<?php echo $category->getUrl()?>">
<?php echo $category->getName()?>
</a>
<?php $subCategories = Mage::getModel('catalog/category')->load($category->getId())->getChildren();
$subCategoryIDs = explode(',',$subCategories);?>
<?php if(count($subCategoryIDs) > 1):?>
<ul>
<?php foreach($subCategoryIDs as $subCat) :?>
<li>
<?php $subCategory = Mage::getModel('catalog/category')->load($subCat); ?>
<a href="<?php echo $subCategory->getUrl()?>">
<?php echo $subCategory->getName()?>
</a>
</li>
<?php endforeach;?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment