Skip to main content

Add following codeTry Below Snippet:

$catId = 3; // Parent Category ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$cnt = 0;
$subcats = $subcategory->getChildrenCategories();
    foreach ($subcats as $subcat) {
        $cnt++;
        echo $subcat->getName();
        if($cnt == 4)
             break;
    }
}

Add following code

$catId = 3; // Parent Category ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$cnt = 0;
$subcats = $subcategory->getChildrenCategories();
    foreach ($subcats as $subcat) {
        $cnt++;
        echo $subcat->getName();
        if($cnt == 4)
             break;
    }
}

Try Below Snippet:

$catId = 3; // Parent Category ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$cnt = 0;
$subcats = $subcategory->getChildrenCategories();
    foreach ($subcats as $subcat) {
        $cnt++;
        echo $subcat->getName();
        if($cnt == 4)
             break;
    }
}
Source Link
user55548
  • 599
  • 1
  • 5
  • 15

Add following code

$catId = 3; // Parent Category ID
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$cnt = 0;
$subcats = $subcategory->getChildrenCategories();
    foreach ($subcats as $subcat) {
        $cnt++;
        echo $subcat->getName();
        if($cnt == 4)
             break;
    }
}