Show top level categories in magento.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?php
$obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat  = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');

foreach ($store_cats as $cat) {
 if ($cat->getName() == $current_cat) {
  echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
  foreach ($obj->getCurrentChildCategories() as $subcat) {
   echo '<li><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";
 }
}
?>

Comments

Popular posts from this blog

Category Name with Products in Cart Page Magento

Safe name of a file by php

Sort Products by popularity count in Magento