How to show the subcategories on a category's frontend page?

i wanna implements subcategories in category landing page .how can i do it?

Want to implement for 3rd level category also .

What exacty you want to show, are you want to show the subcategories on the category page, and further upto 3 level ?

Yes ,I want to show the categories

.i am displaying parent categories with secondlevel category in home page and my question is if i click the subcategory(2ndlevel category) it redirects to new page and it will show the all categories with their info(3rd level category)

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
$subcats = $category->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
?>
<ul>
    <?php
    foreach ($subcats as $subcat) {
        if ($subcat->getIsActive()) {
            $_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
            $_outputhelper = $this->helper('Magento\Catalog\Helper\Output');
            $subcaturl = $subcat->getUrl();

            $_imgHtml = '';
            if ($_imgUrl = $_category->getImageUrl()) {

                $_imgHtml = '<img src="' . $_imgUrl . '" />';
                $_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');

                /* @escapeNotVerified */
                echo '<li><a href="' . $subcaturl . '" class="block-promo" title="' . $subcat->getName() . '">' . $_imgHtml . '<span style="background-color: rgba(255,255,255,0.9)" class="content bg-white"><strong>Place custom code here</strong><br><br><span class="action more button">Learn More</span></span></a></li>';
            }
        }
    } ?>
</ul>

here i did it http://carolinamicrowave.com/

hai sandeep

Thanks for your reply.will it show the categories with their subcaategory with link?Where did you call this template?Please reply

Yes, it will work in frontend end and also in backend, i have put this code in my custom template and set this template above toolbar through xml, you can also directly put this code on yourtheme/magento/catalog/product/list.phtml above the toolbar.

If i want seperate page means for category means.what i wanna do?if u possible can u please share screen shots of yours.

I did’t get your point.

I want separate pages subcategories(2nd and 3rd level category )That means if i click the second level category in home page i will redirect to new page and this page will contains all the 3rd level categories.

Hai sandeep,

I can’t able to get the children collection by using above code.
I have put the code in one new template not list.html.
Can u please Reply?

hi

it returns nothing ($subcats collection is empty).What is the issue?

Have it contains subcategories ?If yes then try run the indexer.

okay .

Where does this code need to be added to get subcategories on the category page like you did with carolinamicrowave.com