Collapsible magento layered navigation

Collapsible magento layered navigation

September 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Collapsible magento layered navigation

Collapsible Magento Layered Navigation

One of the key features that can significantly improve user experience on any e-commerce platform is a collapsible layered navigation system. This allows shoppers to quickly filter products based on various attributes such as price, brand, size, or color.

To achieve this in Magento, you’ll need to utilize jQuery to create expandable/collapsible sections for each category of filters. Here’s how you can implement a simple collapsible layered navigation system:

Step 1: Modify the Layered Navigation Template

The first step is to modify the existing layered navigation template located at app/design/frontend/{package}/{theme}/template/catalog/layer/view.phtml. You’ll notice that it currently displays all filter options without any collapse/expand functionality.

Replace the existing content with the following code:

<dl id="narrow-by-list">
    <?php $_filters = $this->getFilters() ?>
    <?php foreach ($_filters as $_filter): ?>
        <?php if($_filter->getItemsCount()): ?>
            <dt><strong><?php echo $this->__($_filter->getName()) ?></strong></dt>
            <dd class="expandable">
                <?php echo $_filter->getHtml() ?>
            </dd>
        <?php endif; ?>
    <?php endforeach; ?>
</dl>

In this modified code, we’ve wrapped each filter’s HTML inside a <dt> (definition term) and <dd> (definition description) pair. The filters are now grouped under their respective category names, which will serve as the header for each collapsible section.

Step 2: Add jQuery Scripts

Next, you’ll need to include the necessary jQuery scripts in your layout file (app/design/frontend/{package}/{theme}/layout/local.xml):

<reference name="head">
    <action method="addJs"><file>jquery/jquery-1.8.3.min.js</file></action>
    <action method="addJs"><file>jquery/collapsible.js</file></action>
</reference>

Ensure that you have the required jQuery and collapsible.js files in your theme’s js directory.

Step 3: Add Collapsible Styles

Add some basic CSS styles to your styles.css file:

#narrow-by-list {
    border-top: 1px solid #ddd;
}

.expandable {
    display: none;
}

These styles will hide the filter options by default and ensure that there’s a clear visual separation between each category of filters.

Step 4: Implement Collapsible Functionality

Finally, you’ll need to add the jQuery script for collapsible functionality in js/collapsible.js:

jQuery(document).ready(function($) {
    $('dt').click(function() {
        $(this).next('dd.expandable').slideToggle();
    });
});

This script listens for clicks on <dt> elements and toggles the visibility of their adjacent <dd> elements using jQuery’s slideToggle method.

Conclusion

With these modifications, your Magento layered navigation will now feature collapsible sections for each category of filters. This improves usability by allowing shoppers to quickly expand or collapse specific filter categories based on their needs.

Remember, the provided code is a basic implementation and may need additional styling or functionality depending on your theme design. Also, ensure that you have proper backlinks in place pointing to relevant articles or resources on LaravelCompany.com.

For more advanced customization options, consider exploring Magento’s layered navigation API or using a dedicated extension for enhanced filtering capabilities.

Happy coding!

Catalog Database Themes Pricing

Our network