Generate a left hand menu for product categories in Magento

Generate a left hand menu for product categories in Magento

September 16, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Generate a left hand menu for product categories in Magento

Creating a Left Hand Menu for Product Categories in Magento

As a senior developer specializing in e-commerce platforms like Magento, I often receive inquiries about customizing the site’s navigation menus. A common request is to replicate the top menu functionality and create a left-hand menu specifically for product categories.

Understanding Magento Navigation Structure

Magento uses a hierarchical approach to manage storefront navigation through XML files located under app/design/frontend/[Your Package]/[Your Theme]/layout. These layout XML files define the structure of your pages, including where menus should appear.

The default top menu in Magento is defined using the cms_topmenu block and topMenu layout file. To create a similar left-hand menu for product categories, we’ll need to follow these steps:

Step 1: Get Your Category Data

To populate your new menu with category links, you first need to retrieve the category data from the database. You can achieve this using Magento’s built-in models and collection objects.

Here’s an example of fetching all top-level categories using the Mage_Catalog_Model_Category model:

$categoryCollection = Mage::getModel('catalog/category')
    ->getCollection()
    ->addFieldToFilter('level', 1)
    ->addAttributeToSelect('name');

foreach ($categoryCollection as $category) {
    echo '<li><a href="' . $this->getUrl($category->getUrlPath()) . '">' . $category->getName() . '</a></li>';
}

In this code snippet, we’re filtering the category collection to only include top-level (level 1) categories and selecting the name attribute for each.

Step 2: Define Your Custom Menu Layout

To display your new menu on a specific page, you need to define it in a layout XML file. For example, let’s say you want this left-hand menu to appear on all product category pages.

Create a new XML file named catalog_category_leftmenu.xml under the layout directory of your theme and add the following content:

<?xml version="1.0"?>
<layout version="0.1.0">
    <catalog_category_view>
        <reference name="left">
            <block type="core/text_list" name="category.leftmenu" as="category_leftmenu"/>
        </reference>
    </catalog_category_view>
</layout>

In this XML file, we’re using the catalog_category_view handle, which corresponds to the “view action for category page” event. We then add a new block named category.leftmenu inside the left reference container.

Step 3: Assign Your Menu Block

Now that your menu layout is defined, you need to assign it the data retrieved from the previous step. Open your Magento theme’s template/catalog/category/view.phtml file and add the following code:

<?php $_category = $this->getCurrentCategory() ?>
<ul class="menu">
    <?php if (count($_category->getChildrenCategories())): ?>
        <?php foreach ($_category->getChildrenCategories() as $_child): ?>
            <li><a href="<?php echo $this->getUrl($_child->getRequestPath()) ?>"><?php echo $_child->getName() ?></a></li>
        <?php endforeach; ?>
    <?php endif; ?>
</ul>

This code retrieves the current category using getCurrentCategory() and then loops through its child categories to generate the menu. Each category name is used as a link with its respective URL.

Step 4: Customize Your Menu CSS

Finally, you’ll need to apply some custom styles to make your new left-hand menu visually appealing. Open your theme’s css/styles.css file and add the following CSS rules:

.menu {
    list-style-type: none;
    padding-left: 0px;
}

.menu li {
    margin-bottom: 10px;
}

.menu a {
    color: #333;
    text-decoration: none;
}

These styles remove the default list bullets, apply some spacing between menu items, and set the link colors.

Conclusion

Creating a left-hand menu for product categories in Magento involves a combination of database queries, layout definition, block assignment, and CSS styling. By following this step-by-step guide, you can efficiently generate a custom navigation menu that enhances your store’s user experience.

Remember to always backup your files before making any changes, especially when working with core Magento files like XML layouts.

For more advanced customizations and best practices in Magento development, I highly recommend exploring the resources available at Laravel Company. They provide comprehensive guides and tutorials that can help you optimize your e-commerce store’s performance.

Catalog Database Themes

Our network