Hello,
How can i display sub categories into layered navigation while redirect into category page from navigation menu ?
I enabled yes into Anchor field of Manage category (backend) but still it's not displaying into frontend.
Magento Version : 2.2.6
Theme : Ves Fasony free version and it's brand module also
Please suggest me how can i solve it ?
Thanks in advance
Solved! Go to Solution.
Otherwise, you can override category_filter.phtml template file in your theme,
<!--Product List page side bar section -->
<div class="side-products" data-mage-init='{"productSideBar":{"productSideBarSelector": ".category-sidebar-title"}}'>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryD = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
$catPath = $categoryD->getPath();//Get Current Category
$explodedPath = explode("/", $catPath);
$parentCategoryId = $explodedPath[2];
$category = $objectManager->get('Magento\Catalog\Model\Category')->load($parentCategoryId);
?>
<?php if ($category): ?>
<?php
$subcats = $category->getChildrenCategories();
if (count($subcats) > 0) {
?>
<?php foreach ($subcats as $cat) { ?>
<div class="block-category-list dckap-list">
<?php $subsubcats = $cat->getChildrenCategories();
$class = "";
if (count($subsubcats) < 1) $class = "hide-arrow";
?>
<div class="block-title <?php echo $class; ?> category-sidebar-title">
<a href="<?php echo $cat->getUrl() ?>"
<strong><?php echo $cat->getName() ?></strong>
</a>
</div>
<div class="block-content category-sidebar-content">
<?php if (count($subsubcats) > 0) {
?>
<ol class="items">
<?php
foreach ($subsubcats as $subsubcat) {
?>
<li class="item">
<a href="<?php echo $subsubcat->getUrl() ?>"><?php echo $subsubcat->getName() ?></a>
</li>
<?php
}
?>
</ol>
<?php } ?>
</div>
</div> <?php } ?>
<script type="text/javascript">
require([
'jquery'
], function ($) {
$("#layered-filter-block").before($(".block.block-category-list"));
});
</script>
<?php
}
?>
<?php endif; ?>
</div>
Need to override following model :
Magento\CatalogSearch\Model\Layer\Filter\Category
Override by creating new Module and in di.xml file by following way :
<preference for="Magento\CatalogSearch\Model\Layer\Filter\Category" type="Vendor\Module\Model\Layer\Filter\Category" />
Reference : https://magento.stackexchange.com/questions/175841/magento-2-how-to-show-all-active-categories-in-la...
Otherwise, you can override category_filter.phtml template file in your theme,
<!--Product List page side bar section -->
<div class="side-products" data-mage-init='{"productSideBar":{"productSideBarSelector": ".category-sidebar-title"}}'>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$categoryD = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
$catPath = $categoryD->getPath();//Get Current Category
$explodedPath = explode("/", $catPath);
$parentCategoryId = $explodedPath[2];
$category = $objectManager->get('Magento\Catalog\Model\Category')->load($parentCategoryId);
?>
<?php if ($category): ?>
<?php
$subcats = $category->getChildrenCategories();
if (count($subcats) > 0) {
?>
<?php foreach ($subcats as $cat) { ?>
<div class="block-category-list dckap-list">
<?php $subsubcats = $cat->getChildrenCategories();
$class = "";
if (count($subsubcats) < 1) $class = "hide-arrow";
?>
<div class="block-title <?php echo $class; ?> category-sidebar-title">
<a href="<?php echo $cat->getUrl() ?>"
<strong><?php echo $cat->getName() ?></strong>
</a>
</div>
<div class="block-content category-sidebar-content">
<?php if (count($subsubcats) > 0) {
?>
<ol class="items">
<?php
foreach ($subsubcats as $subsubcat) {
?>
<li class="item">
<a href="<?php echo $subsubcat->getUrl() ?>"><?php echo $subsubcat->getName() ?></a>
</li>
<?php
}
?>
</ol>
<?php } ?>
</div>
</div> <?php } ?>
<script type="text/javascript">
require([
'jquery'
], function ($) {
$("#layered-filter-block").before($(".block.block-category-list"));
});
</script>
<?php
}
?>
<?php endif; ?>
</div>