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:
[crayon-63d3e79ea3b0b320907880/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.