I have category structure like this.

  1. Shirts:

    • Male.
    • Female.
  2. Pents:

    • Male.
    • Female.

What I'm trying is get the category ID by giving passing the parameter like 'Petns/Male' or something like this. I spent an almost complete day to find a solution but didn't get any help.

Looking forward to Hint/Solution.


  • Please explain in details so that we can understand easily to solve your problem. – Soumik Rana Apr 20 '17 at 10:43

Below code Put in your phtml file. @parentCategoryId pass category id.

$categoryChild = Mage::helper('your_helper')->getCustomMenuCategory($parentCategoryId);
if (count($categoryChild) > 0) {
    <div class="child-category">
        <ul class="child-subcategories">
            <?php foreach ($categoryChild as $child): ?>
                    <a href="<?php echo $child->getUrl() ?>">
                        <span><?php echo $child->getName() ?></span></a>
            <?php endforeach; ?>

and below in your helper

public function getCustomMenuCategory($categoryId) {

    try {            
            $categoryChild = Mage::getModel('catalog/category')->load($categoryId)->getChildrenCategories();
            if (count($categoryChild) > 0) {
                return $categoryChild;
            } else {
                $parentcategories = Mage::getModel('catalog/category')->load($categoryId)->getParentCategory()->getChildrenCategories();
                return $parentcategories;
    } catch (Exception $ex) {
        Mage::log($ex, null, 'subcategory.log');

Hope this will work. If this will work for you then accept it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.