To get all level categories name and url…

1
33
views
<?php
Advertisement

require_once ‘app/Mage.php’;

Mage::app();

$category = Mage::getModel(‘catalog/category’);

$tree = $category->getTreeModel();

$tree->load();

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

$arr = array();

if ($ids):

foreach ($ids as $id){

$cat = Mage::getModel(‘catalog/category’);

$cat->load($id);

if($id != 3):

if($cat->getIsActive()):

$catName[] =  $cat->getName();

$path[] = $cat->getUrl();

endif;

endif;

}

?>

<?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;

}

?>

If these post is useful to you than please give your feedback.

– Mayank Zalavadia

1 COMMENT

  1. How I get a second root category which is non sub-category of default?
    Yes I need a second root category, I get this about $category = Mage::getModel('catalog/category')->load('id') with all category informations, but non products which in it! 🙁