Magento : Get all categories collection

You can get all categories collection in Magento.

Please find the sample code below:

$categories = Mage::getModel(‘catalog/category’)->getCollection()
->addAttributeToSelect(‘id’)
->addAttributeToSelect(‘name’)
->addAttributeToSelect(‘url_key’)
->addAttributeToSelect(‘url’)
->addAttributeToSelect(‘is_active’);

foreach ($categories as $category)
{
if ($category->getIsActive()) {
$entity_id = $category->getId();
$name = $category->getName();
$urlKey = $category->getUrlKey();
$urlPath = $category->getUrl();
}
}

Leave a Reply