Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Category name in Magento?

I’m new to Magento. I have a 'select-box' that list all the main 'categories-name'. How to get 'Category-name' in Magento?

like image 391
Sajeev Rajan Avatar asked Dec 15 '22 10:12

Sajeev Rajan


1 Answers

<select>
<?php
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();

$ids = $tree->getCollection()->getAllIds();

if ($ids)
{
     foreach ($ids as $id)
  {
     $cat = Mage::getModel('catalog/category');
     $cat->load($id);
     if($cat->getLevel()==1 && $cat->getIsActive()==1)
     {
        echo "<option>";
        echo $cat->getName();
        echo "</option>";
     }
  }
} 
?>
</select>
like image 98
Sajeev Rajan Avatar answered Jan 01 '23 19:01

Sajeev Rajan