Magento: Showing sibling categories in layered navigation

Magento: Showing sibling categories in layered navigation

August 26, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento: Showing sibling categories in layered navigation

Enhancing Magento Layered Navigation: Displaying Sibling Categories

In Magento, layered navigation is a powerful tool that allows customers to filter products based on various attributes such as price, brand, color, and category. However, by default, it only displays the current category’s subcategories in the “Shop by Category” section.

If you want to extend this functionality to include sibling categories when a customer is navigating within a subcategory, there are several steps involved. This involves modifying the Magento core files and adding custom code.

Understanding the Problem

Let’s consider an example: You have a category structure like this:

  • Animals
    • Cats
    • Dogs
    • Lions

Currently, when a customer navigates to the “Cats” subcategory, the layered navigation only shows its own subcategories (if any) and not the sibling categories (“Dogs” and “Lions”).

The Solution: Customizing Layered Navigation

To achieve this, you’ll need to create a custom extension that extends the core Magento_Catalog module. Here’s an overview of the process:

  1. Create the required directories and files:

    In your app/code/customextension/Magento/Catalog/etc, create or update the following files:

    • module.xml: Define your module’s configuration.
    • di.xml: Configure your custom plugin.
  2. Create the custom plugin:

    Create a new file at app/code/customextension/Magento/Catalog/view/frontend/templates/navigation/layer/filter.phtml. This is where you’ll insert your custom logic for displaying sibling categories.

Implementing the Custom Logic

In the filter.phtml file, you’ll need to use Magento’s object manager and reflection to access the category model directly. Here’s a simple example of how this might look:

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryHelper = $objectManager->get('Magento\Catalog\Helper\Category');
$siblingCategories = $categoryHelper->getCurrentCategory()->getParentCategory()->getChildrenCategories();

foreach ($siblingCategories as $siblingCategory) {
    echo '<a href="' . $siblingCategory->getUrl() . '">' . $siblingCategory->getName() . '</a><br />';
}
?>

This code retrieves the parent category of the current subcategory and then loops through its children to display the sibling categories.

Remember: Magento 2 Coding Standards

It’s important to note that using the ObjectManager directly is not recommended in production code. This example is for illustrative purposes only. In a real-world scenario, you should use dependency injection as per Magento’s coding standards.

Conclusion

Displaying sibling categories in Magento layered navigation requires custom development and an understanding of how Magento handles category relationships. By following the steps outlined above—creating a custom module, modifying core templates, and using object manager for accessing necessary data—you can enhance your site’s user experience with this additional filtering functionality.

Remember to thoroughly test any changes you make to ensure they don’t negatively impact other areas of your store. If you need further assistance or want to discuss how to implement this in a production environment, feel free to reach out to the experts at Laravel Company.

This customization requires a solid understanding of Magento’s architecture and the ability to work with its object model. It’s a great way to demonstrate your development skills while providing value to your customers.

Stay tuned for more advanced Magento tips and tricks!

Catalog Extensions Themes Configuration

Our network