By default Magento collapse all filters in layered navigation. So if you want to expand only “Category” filter please follow below steps.
First you have to override below PHTML file in your theme:
1 |
vendor/magento/module-layered-navigation/view/frontend/templates/layer/view.phtml |
Like:
1 |
app/design/frontend/[VENDOR_THEME_NAME]/[THEME_NAME]/Magento_LayeredNavigation/templates/layer/view.phtml |
After overriding above PHTML file find below code and replace with new code (Around line no. 33 to 42):
1 2 3 4 5 6 7 8 9 10 |
<?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()): ?> <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; ?> |
Replace with this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?php foreach ($block->getFilters() as $filter): ?> <?php if ($filter->getItemsCount()): ?> <?php if (!$wrapOptions): ?> <?php $collapsibleRange = ''; $cat = __('Category'); if($filter->getName() == $cat){ $collapsibleRange = $catcount; } $catcount++; ?> <strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* @escapeNotVerified */ echo __('Shopping Options') ?></strong> <dl class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $collapsibleRange ?>", "multipleCollapsible": false}}'> <?php $wrapOptions = true; ?> <?php endif; ?> <div data-role="collapsible" class="filter-options-item"> <div data-role="title" class="filter-options-title"><?php /* @escapeNotVerified */ echo __($filter->getName()) ?></div> <div data-role="content" class="filter-options-content"><?php /* @escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div> </div> <?php endif; ?> <?php endforeach; ?> |
After doing all steps please clean the cache php bin/magento cache:clean and check in front-end categories page category filer is expand like below image:
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-6287789bdec11603127587/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...
If you want get query string params in controller file,...