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.

  • Unsetting the category as anchor should work, have you tried at the store level as well? – Amit Naraniwal Feb 8 at 7:13
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; ?>
...
...
  • This unfortunately did not work for me. – Martijnr Jun 4 '18 at 1:45
  • @Martijnr face any issue? – Prince Patel Jun 4 '18 at 5:02
  • This did not change anything. Any other suggestions Prince? – Martijnr Jun 4 '18 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

  • 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 Jun 4 '18 at 23:49

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.