How to make sidebar categories dynamic

firstly open your magento folder and then
enter in this path: app/design/frontend/default/and ur theme name/template/callout/and then open left.phtml for left sidebar or right.phtml for right sidebar.

then open the file (left.phtml/right.phtml)


then comment all the code of left.phtml/right.phtml sidebar

and then paste this code to ur (left.phtml/right.phtml)file

code


<div class="link">
    <div class="product"><a href="#">Products</a></div>
    
     <?php  
 
 $category = Mage::getModel ( 'catalog/category' ); // instanciate the class  
    $tree = $category->getTreeModel(); // get the model  
    $rootid = Mage::app()->getStore()->getRootCategoryId(); // get the root id so we can get all main cats (main cats are children of root)  
    $category->load($rootid); // load up the root  
    $ids = $category->getChildren(); // get the children of the root (the main categories)  
    $maincatsid = explode(",", $ids); // get the ids in to an array  
      
    foreach ($maincatsid as $maincatid){  ?> 
     <?php $maincat = $category->load($maincatid);  // load up the main cat  ?>
 <div class="Golf"><a href="<?php echo Mage::getModel("catalog/category")->load($maincatid)->getUrl() ?>"><?php echo $maincat->getName(); ?></a></div>
                <?php } ?>    
    
    
    </div>

and after that save the file

Hope this will help you!





Comments

  1. It's really very important, i think you have done fantastic job
    thanks for sharing it.
    Friendship forever

    ReplyDelete

Post a Comment