2

I would like to remove the categories section on the layered navigation but do not see where they are called within layered navigation module.

2
  • Are you using multiple languages? Commented Aug 17, 2018 at 9:15
  • No, just english. It is the sub-categories that are displayed in Layered Navigation.
    – Nick Piro
    Commented Aug 17, 2018 at 9:16

4 Answers 4

2

Copy the following file:

/vendor/magento/theme-frontend-luma/Magento_LayeredNavigation/templates/layer/view.phtml

to your theme:

app/design/frontend/Vendor/Theme/Magento_LayeredNavigation/templates/layer/view.phtml

And put the Category condition like below:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Category layered navigation
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation
 */
?>

<?php if ($block->canShowBlock()): ?>
    <div class="block filter">
        <div class="block-title filter-title">
            <strong><?= /* @escapeNotVerified */ __('Shop By') ?></strong>
        </div>

        <div class="block-content filter-content">
            <?= $block->getChildHtml('state') ?>

            <?php if ($block->getLayer()->getState()->getFilters()): ?>
                <div class="block-actions filter-actions">
                    <a href="<?= /* @escapeNotVerified */ $block->getClearUrl() ?>" class="action clear filter-clear"><span><?= /* @escapeNotVerified */ __('Clear All') ?></span></a>
                </div>
            <?php endif; ?>
            <?php $wrapOptions = false; ?>
            <?php foreach ($block->getFilters() as $filter): ?>
                <?php if (!$wrapOptions): ?>
                    <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?= /* @escapeNotVerified */ __('Shopping Options') ?></strong>
                    <dl class="filter-options" id="narrow-by-list">
                <?php $wrapOptions = true; endif; ?>
                    <?php if ($filter->getItemsCount() && $filter->getName() != 'Category'): ?>
                        <dt role="heading" aria-level="3" class="filter-options-title"><?= $block->escapeHtml(__($filter->getName())) ?></dt>
                        <dd class="filter-options-content"><?= /* @escapeNotVerified */ $block->getChildBlock('renderer')->render($filter) ?></dd>
                    <?php endif; ?>
            <?php endforeach; ?>
            <?php if ($wrapOptions): ?>
                </dl>
            <?php endif; ?>
        </div>
    </div>
<?php endif; ?>

Use the above content for your view.phtml file.

4
  • This worked to remove the categories but broke the mobile. The 'Shop By' button becomes unclickable. When I revert the changes, the button then works.
    – Nick Piro
    Commented Aug 17, 2018 at 9:30
  • Are you working with luma theme or parent theme is luma theme? Commented Aug 17, 2018 at 9:32
  • I built custom theme based on Luma.
    – Nick Piro
    Commented Aug 17, 2018 at 9:33
  • I have updated my answer. You need to copy the view.phtml from vendor/magento/theme-frontend-luma/Magento_LayeredNavigation/templates/layer/view.phtml Commented Aug 17, 2018 at 9:34
7

Checked with M2.4.1. There is a configuration here Store -> Configuration -> Catalog -> Catalog

enter image description here

1
  • 1
    this answer is best i've never seen. you're great.
    – madagaskar
    Commented Nov 3 at 13:27
1

In Magento 2.3.4:

  1. copy file vendor/magento/theme-frontend-luma/Magento_LayeredNavigation/templates/layer/view.phtml to /Magento_LayeredNavigation/templates/layer/view.phtml
  2. Find <?php if ($filter->getItemsCount()) : ?>
  3. Replace with <?php if ($filter->getItemsCount() && get_class($filter) != \Magento\CatalogSearch\Model\Layer\Filter\Category::class) : ?>
0

The layered navigation categories are called in one of the core files as below:

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

You need to override this file in your theme and then change the content of the file however you want.

Add below directory in your theme:

app/design/frontend/vendor_name/theme_name/Magento_LayeredNavigation/templates/layer

Then put above file view.phtml in this path.

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.