How to display all categories in magento project -
am new magento 1.7 , using celebrity theme want add categories displayed in left side bar , have browsed through n tried many none of them working (may due celebrity theme). can 1 me on asap. please
you can add
go layout.xml , add this
/app/design/frontend/default/default/layout/catalog.xml
open xml file , paste code.
<reference name="left"> <block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml" /> </reference>
open file ..
/app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml
paste code:
<?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 $cat) { if ($cat->getname() == $current_cat) { echo '<li class="current"><a href="'.$this->getcategoryurl($cat).'">'.$cat->getname()."</a>\n<ul>\n"; foreach ($obj->getcurrentchildcategories() $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"; } } ?>
edit
list categories
$_helper = mage::helper('catalog/category') ?> <?php $_categories = $_helper->getstorecategories() ?> <?php $currentcategory = mage::registry('current_category') ?> <?php if (count($_categories) > 0): ?> <ul> <?php foreach($_categories $_category): ?> <li> <a href="<?php echo $_helper->getcategoryurl($_category) ?>"> <?php echo $_category->getname() ?> </a> <?php //if ($currentcategory && $currentcategory->getid() == $_category->getid()): ?> <?php $_category = mage::getmodel('catalog/category')->load($_category->getid()) ?> <?php $_subcategories = $_category->getchildrencategories() ?> <?php if (count($_subcategories) > 0): ?> <ul> <?php foreach($_subcategories $_subcategory): ?> <li> <a href="<?php echo $_helper->getcategoryurl($_subcategory) ?>"> <?php echo $_subcategory->getname() ?> </a> <?php $_category1 = mage::getmodel('catalog/category')->load($_subcategory->getid()) ?> <?php $_subcategories1 = $_category1->getchildrencategories() ?> <?php if (count($_subcategories1) > 0): ?> <ul> <?php foreach($_subcategories1 $_subcategory1): ?> <li> <a href="<?php echo $_helper->getcategoryurl($_subcategory1) ?>"> <?php echo $_subcategory1->getname() ?> </a> </li> <?php endforeach; ?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul> <?php endif; ?> <?php // endif; ?> </li> <?php endforeach; ?> </ul> <?php endif;?>
Comments
Post a Comment