cancel
Showing results for 
Search instead for 
Did you mean: 

How to display subcategories in Mageplaza Layered Menu (Porto Theme)

How to display subcategories in Mageplaza Layered Menu (Porto Theme)

As stated In wonder if anyone can help figure out how to do this. How to display subcategories in Mageplaza Layered Menu (Porto Theme) and when going into subcategories the menu should still be visable.

The file in fact that should be changes would be this.

 

Please advice.

app\design\frontend\Smartwave\porto\Mageplaza_LayeredNavigation\templates\layer\category_filter.phtml

 

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category'); //Get Current Category
?>
<?php if($category): ?>
<?php 
$subcats = $category->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
    if(count($subcats)>0){
?>
<div class="block-category-list">
    <div class="block-title">
        <strong><?php echo $category->getName() ?></strong>
    </div>
    <div class="block-content">
        <ol class="items">
        <?php
        foreach($subcats as $subcat){ 
        ?>
            <li class="item">
                <a href="<?php echo $subcat->getUrl() ?>"><?php echo $subcat->getName() ?></a>
            </li>
        <?php
            }
        ?>
        </ol>
    </div>
    <script type="text/javascript">
    require([
        'jquery'
    ], function ($) {
        $("#layered-filter-block").before($(".block.block-category-list"));
    });
    </script>
</div>
<?php
    }
?>
<?php endif; ?>
1 REPLY 1

Re: How to display subcategories in Mageplaza Layered Menu (Porto Theme)

You have to go to app/design/frontend/theme/template/catalog/product/list.phtml.
This is your category listing page.
Here you can put the code:

<?php
$currCategoryId = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load($currCategoryId);
$subcategories = $category->getChildrenCategories();
if(count($subcategories)>0){
$count=1;
foreach ($subcategories as $subcategory) {
$category1 = Mage::getModel('catalog/category')->load($subcategory->getId());
$subcategories1 = $category1->getChildrenCategories();
echo $subcategory->getName()."<br/>";
if(count($subcategories1)>0){

foreach ($subcategories1 as $thirdLevelCategory) {
echo "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp";
echo $thirdLevelCategory->getName()."<br/>";
}
}
}

}
?>

Note: It's better to create a block and load your data from the block or you can create a helper in your module and use that in your template.

If issue solved, Click Kudos & Accept as Solution.
LitCommerce - The Most Simple & Affordable Multi-channel Selling Tool