1

in Magento 2.1, I would like to have the Category filter removed from the sidebar when in the shop category page, leaving the price filter untouched.

So far I have tried unsetting the category as anchor, which doesn't change anything. I am able to remove the whole sidebar with XML, but that's not ideal because I want to keep using the price filter.

1
  • Unsetting the category as anchor should work, have you tried at the store level as well? Commented Feb 8, 2019 at 7:13

3 Answers 3

1

Override view.phtml file in your theme

From

vendor/magento/module-layered-navigation/view/frontend/templates/layer/view.phtml

To

app/design/frontend/{Vendor}/{theme}/Magento_LayeredNavigation/templates/layer/view.phtml

Now set condition for category before $filter->getItemsCount(),

<?php  

if($filter->getName() != __('Category')) {
    ...
    ...
} 

?>

Final code looks like this

...
...
<?php $wrapOptions = false; ?>
<?php foreach ($block->getFilters() as $filter): ?>
  ...
    <?php  if($filter->getName() != __('Category')) : ?>
        <?php if ($filter->getItemsCount()): ?>
            <dt role="heading" aria-level="3" class="filter-options-title"><?php echo $block->escapeHtml(__($filter->getName())) ?></dt>
            <dd class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></dd>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>
...
...
3
  • This unfortunately did not work for me.
    – Martijnr
    Commented Jun 4, 2018 at 1:45
  • @Martijnr face any issue? Commented Jun 4, 2018 at 5:02
  • This did not change anything. Any other suggestions Prince?
    – Martijnr
    Commented Jun 4, 2018 at 23:47
0

I am assuming you are referring cart page as shopping page.

In your theme, checkout_cart_index.xml add <referenceBlock name="catalog.leftnav" remove="true" /> as follows

<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalog.leftnav" remove="true" />
    </body>
</page>

Default Magento doesn't have layered navigation on cart page.

To remove it from every where you can use above in your theme default.xml or in catalog_category_view_type_default.xml

1
  • I edited my post, what I mean is the shop category page. When I use your XML code, it removes the complete sidebar including the price filter. I only want the category filter to be removed.
    – Martijnr
    Commented Jun 4, 2018 at 23:49
0

You can hide subcategory filter from admin as below

Store > configuration > catalog > catalog > Layered Navigation > Display Category Filter set to NO

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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