I have a situation where I have 2 layers of categories, one inside the other

I want to list the same products in the top level category as I use in the 2nd level sub categories. However I only want one set of attributes to show in the top level layered navigation, then another set of attributes in the 2nd level layered navigation. So for example, if I have this structure…

Washing Machines
- Top Loading Washers
- Front Loading Washers
- Washer Dryer Combo

…in the top level 'Washing Machines' layered navigation I want to show the labels for Machine Type as "Top Loading Washers", "Front Loading Washers", "Washer Dryer Combo" then in the second level for each machine type I want to show the layered nav for Machine Capacity as "3kg", "4kg", "6kg".

I don't want to show the Machine Capacity in the top level navigation and I don't want to show the Machine Type in the sub categories. Is it possible to filter out attributes used in layered navigation so only one set is used in the top level and another set is used in the sub category while using the same product in both categories? Thanks


Layered navigation filters are rendered in catalog/layer/view.phtml template:

            <?php foreach ($_filters as $_filter): ?>
            <?php if($_filter->getItemsCount()): ?>
                <dt><?php echo $this->__($_filter->getName()) ?></dt>
                <dd><?php echo $_filter->getHtml() ?></dd>
            <?php endif; ?>

Here you can add checks for category and attribute id (replace the code aabove with the code below):

                $_categoryId = $this->getLayer()->getCurrentCategory()->getId();
                $_categoryFilters = array(
                    // top level categories
                        'categories' => array(5,8,10),
                        'attributes' => array('color', 'size'),
                    // second level categories 
                        'categories' => array(6, 7, 9, 11),
                        'attributes' => array('manufacturer'),
            <?php foreach ($_filters as $_filter): ?>
                $_found = false;
                foreach ($_categoryFilters as $_categoryFilter) {
                    if (in_array($_categoryId, $_categoryFilter['categories']) &&
                        (!($_attribute = $_filter->getAttributeModel()) ||
                        in_array($_attribute->getAttributeCode(), $_categoryFilter['attributes']))
                        $_found = true;
            <?php if($_found && $_filter->getItemsCount()): ?>
                <dt><?php echo $this->__($_filter->getName()) ?></dt>
                <dd><?php echo $_filter->getHtml() ?></dd>
            <?php endif; ?>

Basically you what to control what filter to show or hide at given category.

You can easily hide some specific filters from the top categories. Open the category edit page, switch on the "Custom Design" tab and add the following code in the "Custom Layout Update" field:

<reference name="catalog.leftnav">
    <action method="unsetChild"><alias>size_filter</alias></action>

Where "size" it the filter code. So for color use "color_filter" and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.