cancel
Showing results for 
Search instead for 
Did you mean: 

Display subcategories instead of products on a product listing (category) page magento 2.3

SOLVED

Display subcategories instead of products on a product listing (category) page magento 2.3

Hi guys,

I need to display all the subcategories in category page,

https://ibb.co/G9ZWWXM

In 1.9 https://www.creare.co.uk/blog/magento/magento-subcategories-category-pages 

is it possible to create the same in Magento 2.3.2

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Display subcategories instead of products on a product listing (category) page magento 2.3

Hello @raju_a 

 

Please follow the below steps:

 

  1. Create static block
  2. Call phtml file in created static block
  3. Add the code at https://magento.stackexchange.com/questions/120179/get-sub-category-of-current-category-in-magento2  in phtml file to get subcategories
  4. Add CMS static block as shown here: https://drops.meetanshi.com/N1GeZJ
  5. Display mode should be static block only.

Hope the above solution will be helpful to you.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

View solution in original post

4 REPLIES 4

Re: Display subcategories instead of products on a product listing (category) page magento 2.3

Hello @raju_a 

 

Please follow the below steps:

 

  1. Create static block
  2. Call phtml file in created static block
  3. Add the code at https://magento.stackexchange.com/questions/120179/get-sub-category-of-current-category-in-magento2  in phtml file to get subcategories
  4. Add CMS static block as shown here: https://drops.meetanshi.com/N1GeZJ
  5. Display mode should be static block only.

Hope the above solution will be helpful to you.

---
If you've found my answer useful, please give"Kudos" and "Accept as Solution"

Re: Display subcategories instead of products on a product listing (category) page magento 2.3

@Meetanshi ,

Tq very much, I will definitely try, do we have any alternative solution apart from this

Re: Display subcategories instead of products on a product listing (category) page magento 2.3

Hello @raju_a ,

 

To display subcategories information on the category page in Magento 2.

 

Add this below code to your theme ‘list.pthml’ file.
app\design\frontend\Themes\Yourtheme\Magento_catalog\templates\product\list.phtml

```<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
$subcats = $category->getChildrenCategories();                                                  
?>
<div class="product details product-item-details">
    <?php
foreach ($subcats as $subcat) {
     if ($subcat->getIsActive()) {
                                 $sub_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
                                 $subcat_url = $subcat->getUrl(); ?>
            <span class="product-image">
            <a href="<?php echo $subcat_url; ?>">
                     <img src="<?php echo $sub_category->getImageUrl() ?>" height="300px" width="240px">
            </a>            
            </span>
          <span class="product-item-name">
             <a href="<?php echo $subcat_url?>" class="product-item-link"><?php echo $subcat->getName(); ?></a>
             </span>
            <?php                        
     }
} ?>
</div>```
If my answer is useful, please Accept as Solution & give Kudos

Re: Display subcategories instead of products on a product listing (category) page magento 2.3

Hello @raju_a 

try following this blog

http://magecomp.com/blog/display-subcategories-information-category-page-magento-2/
Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now