Created
September 15, 2015 12:06
-
-
Save jasperf/5ed4a6d835c876b1c0e8 to your computer and use it in GitHub Desktop.
Magento Custom Category list
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
<ul class="cat-nav"> | |
<?php | |
$obj = new Mage_Catalog_Block_Navigation(); | |
$storeCategories = $obj->getStoreCategories(); | |
Mage::registry('current_category') ? $currentCategoryId = Mage::registry('current_category')->getId() : $currentCategoryId=''; | |
foreach ($storeCategories as $_category): | |
?> | |
<li class="<?php echo $_category->getName(); ?>"> | |
<?php $categoryChildren = $_category->getChildren(); ?> | |
<?php if($categoryChildren->count()) : ?> | |
<ul> | |
<?php $i=0; ?> | |
<?php foreach($categoryChildren as $_categoryChild) : ?> | |
<?php $_categoryChildModel = Mage::getModel('catalog/category')->load($_categoryChild->getId()); if ($i > 30) break;?> | |
<?php $categoryGrandchildren=$_categoryChild->getChildren(); ?> | |
<li class="<?php echo $_category->getName(); ?>"> | |
<?php | |
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold=''; | |
echo ' ' . '<a href="' . $_categoryChildModel->getUrl() . '"' . $bold . '>' . $_categoryChild->getName() . '' . $_categoryChildModel->getProductCollection() . '</a>'; | |
?> | |
</li> | |
<?php if($categoryGrandchildren->count()) : ?> | |
<?php foreach($categoryGrandchildren as $_categoryGrandchild) : ?> | |
<?php $_categoryGrandchildModel = Mage::getModel('catalog/category')->load($_categoryGrandchild->getId());?> | |
<li> | |
<?php | |
$currentCategoryId===$_categoryChild->getId() ? $bold="style=\"font-weight:bold\"" : $bold=''; | |
echo '  ' . '<a href="' . $_categoryGrandchildModel->getUrl() . '"' . $bold . '>' . $_categoryGrandchild->getName() . '(' . $_categoryGrandchildModel->getProductCount() . ')</a>'; | |
?> | |
</li> | |
<?php $i++; ?> | |
<?php endforeach; ?> | |
<?php endif; ?> | |
<?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