0

I need get first subcategory name in current category how in admin panel. How it possible.

Update:

<?php 
    $layer = Mage::getSingleton('catalog/layer');
    $_category = $layer->getCurrentCategory();
    $currentCategoryId= $_category->getId();
    $children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
    foreach ($children as $category)
    {
          echo $category->getName();
    }
    ?>

with this code i can get all subcategory name in current category, but i need get only first subcategory name - not all list subcategory name

  • 1
    Could you spell out a little more clear what version of magento you are using what you are trying to do, what is the end goal. You question is far to vague to have a clear answer. – circlesix Feb 28 '17 at 22:41
  • i'm use magento 1.9 version, i have category Auto, with subcategories and i need get only first subcategory name in category Auto – Lerry Feb 28 '17 at 22:44
  • 1
    Are you wanting to rename a category Auto? Or are you wanting to create a subcategory named Auto? – Rebel Feb 28 '17 at 23:09
  • i need in my template phtml get first subcategory name in category Auto, with this code: $_category_detail=Mage::registry('current_category'); i can get category name Auto, but i need first subcategory in category Auto – Lerry Feb 28 '17 at 23:15
  • 1
    please update your question with the code that you are using, once we see that, should be able to help troubleshoot it. – circlesix Feb 28 '17 at 23:17
1

You may try the code below to get first subcategory name in the current category

<?php 

    $layer = Mage::getSingleton('catalog/layer');
    $_category = $layer->getCurrentCategory();    
    $currentCategoryId= $_category->getId();    
    $children = Mage::getModel('catalog/category')->getCategories($currentCategoryId,0,false,true);           
    $firstsubcategory =  $children->getFirstItem(); // First Sub Catehory
    echo $firstsubcategory->getName()."<br /><br />";;
    foreach ($children as $category)
    {
          echo $category->getName()."<br />";
    }
    ?>
|improve this answer|||||

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.