How to get all category of a magento store

Magento

Posted on 02 Jun 15 by Vickey
  620



By using below code we can get all category which is come on level 2 if we remove level filter then it will return all parent category and base category

$categories = Mage::getModel('catalog/category')->getCollection()
->addAttributeToSelect('id')
->addAttributeToSelect('name')
->addAttributeToSelect('urlkey')
->addAttributeToSelect('url')
->addAttributeToFilter('level',2)
->addAttributeToSelect('isactive');

foreach ($categories as $category)
{
        $name = $category->getName();
        $url_path = $category->getUrl();

}

if you want to get child categories of a category then you can use this code

$children = Mage::getModel('catalog/category')->getCategories(10);

here 10 is the parent category id


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com