I am using Porto Theme (Magento 2) for building an e-commerce website. I have some categories that has sub-categories, so when I go to that sub-categories page, then it is showing the category filter empty, so I want to remove the category filter only (not price filter) only where further sub-categories are not there. For example: https://www.ekaani.com/brands/ekaani-gods.html
I have tried to remove that, but when I try to edit category_view.xml
page, then the whole sidebar disappears. What I have tried is that adding remove=true
in the last block.
<?xml version="1.0"?>
<!--
/**
* Copyright © 2018 Porto. All rights reserved.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="page.top">
<block class="MagentoCatalogBlockCategoryView" name="category_banner" template="category/banner.phtml" ifconfig="porto_settings/category/category_description" before="-"/>
</referenceContainer>
<referenceContainer name="content">
<block class="MagentoCatalogBlockCategoryView" name="category_desc_main_column" template="category/desc_main_column.phtml" ifconfig="porto_settings/category/category_description" before="category.products"/>
</referenceContainer>
<move element="category.image" destination="content" before="category_desc_main_column"/>
<referenceContainer name="sidebar.main" remove="true">
<block class="SmartwavePortoBlockTemplate" name="category_view_custom_block" after="-" template="Magento_Catalog::category/custom_block.phtml"/>
</referenceContainer>
</body>
</page>
For the mentioned page, I only want to remove the sub-categories that do not have further sub-categories.
Update:
Here is my category_filter.phtml
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$category = $objectManager->get('MagentoFrameworkRegistry')->registry('current_category');
?>
<?php if($category): ?>
<?php
$categoryHelper = $this->helper('MagentoCatalogHelperCategory');
$subcategories=$category->getCategories($category->getId());
if(count($subcategories)>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($subcategories as $subcategory){
if (!$subcategory->getIsActive()) {
continue;
}
?>
<li class="item">
<a href="<?php echo $categoryHelper->getCategoryUrl($subcategory) ?>"><?php echo $subcategory->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; ?>