This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Tuesday 30 October 2012

Magento : get category list on Home page


Actually There are various types to get category List but I suggest two way for this,

1) First One

Simply follow bellow steps to get Category List on Home page,

A) Create a one Phtml file inside

     app/design/frontend/base/default/template/catalog/navigation/

     use file name left_navcategory.phtml

B) Now, Copy below code and paste in left_navcategory.phtml

   <?php
if(Mage::getSingleton('cms/page')->getIdentifier() == 'home'  && Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms') :
?>

<?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 class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul  id='nav_category' class='nav_category'>\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";
    }
}
endif ?>


C) Create one Block for that in Catalog.xml under

<reference name="left">
   <block type="catalog/navigation" name="catalog.left_navcategory" template="catalog/navigation/left_navcategory.phtml" />
</reference>



2) Second One

Just Copy and Paste Below Code in Home Page

<?php $category = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('is_active');

foreach($category as $cat)
{
      if($cat->getId() != 3)
     {
         echo $cat->getName();
     }
}
//print_r($category);

?>





No comments:

Post a Comment