Magento category navigation or vertical category menu in sidebar

Step1. PHP Code to retrieve top level categories for navigation and save it at the following location.

in short this file contain code related to catalog Navigation Model which retrieves top level categories and show it in proper manner

Magento\app\design\frontend\base\default\template\catalog\navigation\categorymenu.phtml
<?php
/**
* Left Category menu for store
* We are showing  jsut the top level categorioes
* @see Mage_Catalog_Block_Navigation
*/
?>
<div>
<div>
<div><h2><?php echo $this->__(‘Categories’) ?></h2></div>
<div>
<ul id=”category-nav”>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php if($_category->name!=””):  ?>
<li><?php echo $this->drawItem($_category) ?></li>
<?php endif?>
<?php endforeach ?>
</ul>
</div>
</div>
</div>

Step2. Change the page.xml to include category navigation menu.

So let’s start with the home page, as in most of the cases. Magento home page is simple CMS page, therefore, we have to locate the page related layout XML file . that exists in our layout folder of selected theme. We are taking example as the default theme. So have to open the following file:


app\design\frontend\base\default\layout\page.xml. Line no. 83  looks like :

<block type=”core/text_list” name=”left” as=”left” translate=”label”>
<label>Left Column</label>
</block>

This section tells us the left hand side section inherit from its parent Catalog  So we have to modify the catalog.xml file located in the same folder  hence open

app\design\frontend\base\default\layout\catalog.xml. it looks like :

the original
<reference name=”left”>
<block type=”core/template” name=”left.permanent.callout” template=”callouts/left_col.phtml”>
<action method=”setImgSrc”><src>images/media/col_left_callout.jpg</src></action>
<action method=”setImgAlt” translate=”alt” module=”catalog”></action>
<action method=”setLinkUrl”><url>checkout/cart</url></action>
</block>
</reference>

we have to update it as follows. hence the modified version is
<reference name=”left”>
<block type=”catalog/navigation” name=”catalog.categorymenu” after=”top.search” template=”catalog/navigation/categorymenu.phtml”/>
<block type=”core/template” name=”left.permanent.callout” template=”callouts/left_col.phtml”>
<action method=”setImgSrc”><src>images/media/col_left_callout.jpg</src></action>
<action method=”setImgAlt” translate=”alt” module=”catalog”></action>
<action method=”setLinkUrl”><url>checkout/cart</url></action>
</block>
</reference>

0

About the author

Janaki(http://mjanaki.com) - A Software developer with 9+ years of experience in multiple technology projects across web, mobile, and cloud applications with expertise in PHP, C#, MySQL, Web services and open source platforms.

Similar Posts

Uninstall MySql on a Mac OS X
VMWare shared folder as apache vhost
Install Redis Server in CentOS

Comments are closed.