List category and subcategory on sidebar – Magento

<?php
 $obj = new Mage_Catalog_Block_Navigation();
 $store_cats = $obj->getStoreCategories();
 $current_cat = $obj->getCurrentCategory();
 $current_cat = (is_object($current_cat) ? $current_cat->getName() : '');?>
 <?php foreach ($store_cats as $cat)
 { if ($cat->getName() == $current_cat) {
  echo '<li style="padding-left:5px;">
  <a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."
  </a>n<ul>n";
 foreach ($obj->getCurrentChildCategories() as $subcat)
{ echo '<li style="padding-left:15px;">
 <a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a>
 </li>n"; }
 echo "</ul>n</li>n"; }
else
 { echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."
 </a></li>n"; }}

?>

55 thoughts on “List category and subcategory on sidebar – Magento”

  1. Hi there, just became aware of your blog through Google, and
    found that it’s truly informative. I’m going to
    watch out for brussels. I’ll appreciate if you continue this in future. Many people will be benefited from your writing. Cheers!

Leave a comment