I have category id .I got the id from this code
<?php echo $current_catid=$this->getCategoryId(); ?>
now i want to check that this category have child category or not .
if it have child than it will show the child category image and name and url.
Using a given code snippet, you can retrieve all the subcategories of the parent without depends on the level type. Call Block Class methods in the template, $parentID = 11; //MEN Category Id $getCategoryList = $this->getSubCategoryByParentID($parentID); <? php if (count($getCategoryList)) { ?>
Magento 2 anchor category is the definition of the category in which the Magento native Layered Navigation can be displayed. If you need to set it as the anchor category then you need to go to Product > Categories > Display settings and switch the Anchor option to Yes. After that, don't forget to save the changes.
If You have current_category id then load category
$category = Mage::getModel('catalog/category')->load(id);
and check count($category->getChildren());
Other methods are for count children
count($category->getChildrenNodes());
$category->getChildrenCount();
This way you can check if category has children or not.
getChildren()
methods give you children category id and based on id you can get category image and category name.
Please try this one, its working fine at my end
<?php
$parentCategoryId = 10;
$categories = Mage::getModel('catalog/category')->load($parentCategoryId)->getChildren();
$catArray = explode(',', $categories);
foreach($catArray as $child)
{
$_child = Mage::getModel( 'catalog/category' )->load( $child );
echo $_child->getName() . '<br />';
echo $_child->getUrl() . '<br />';
echo $_child->getDescription() . '<br />';
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With