January 12, 2010

To get all level categories name and url…

<?php
require_once ‘app/Mage.php’;
Mage::app();
$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();   // we can get all level categories id
if ($ids):
foreach ($ids as $id){
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);
if($id != 3): // if  category id is not “root catalog” id – here root catalog id is 3
if($cat->getIsActive()): // if category is active
$catName[] =  $cat->getName(); //  To get name of the category
$path[] = $cat->getUrl(); // to get url of category
endif;
endif;
}
?>

1 comment:

  1. Thanx Nimesh,
    This is exactly what I am looking for.
    thanx once again.

    Anand Singh

    ReplyDelete