<?php
require_once 'app/Mage.php';
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', 12000);
Mage::app();
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
?>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $categoryId = 12449;?>
<?php $category = Mage::getModel('catalog/category')->load($categoryId) ?>
<?php $_categories = $category->getChildrenCategories() ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>"><?php echo $_category->getName() ?></a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php if($_category->hasChildren()):?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"><?php echo $_subcategory->getName() ?></a>
<?php $_category2 = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
<?php if($_category2->hasChildren()):?>
<?php $_subcategories2 = $_category2->getChildrenCategories() ?>
<ul>
<?php foreach($_subcategories2 as $_subcategory2): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory2) ?>"><?php echo $_subcategory2->getName() ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Second Method
$category_ids = array();
$catID = 12449;
function retrieveAllChilds($id = null, $childs = null) {
$category = Mage::getModel('catalog/category')->load($id);
$subCategory = $category->getResource()->getChildren($category, true);
foreach ($subCategory as $categoryID)
{
$sCategory = Mage::getModel('catalog/category')->load($categoryID);
//$catnames = array();
//$category_ids = array();
foreach ($sCategory->getParentCategories() as $parent) {
//$catnames[] = $parent->getName();
//array_push($category_ids,$parent->getName());
$category_ids[$parent->getId()] = $parent->getName();
}
//echo implode('->',$catnames);
//echo '<br>';
/*echo "<pre>";
print_r($category_ids);*/
}
return $category_ids;
}
$dd = retrieveAllChilds(12449);
echo "<pre>";
print_r($dd);
require_once 'app/Mage.php';
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit', '1024M');
ini_set('max_execution_time', 12000);
Mage::app();
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
?>
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $categoryId = 12449;?>
<?php $category = Mage::getModel('catalog/category')->load($categoryId) ?>
<?php $_categories = $category->getChildrenCategories() ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>"><?php echo $_category->getName() ?></a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php if($_category->hasChildren()):?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"><?php echo $_subcategory->getName() ?></a>
<?php $_category2 = Mage::getModel('catalog/category')->load($_subcategory->getId()) ?>
<?php if($_category2->hasChildren()):?>
<?php $_subcategories2 = $_category2->getChildrenCategories() ?>
<ul>
<?php foreach($_subcategories2 as $_subcategory2): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory2) ?>"><?php echo $_subcategory2->getName() ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Second Method
$category_ids = array();
$catID = 12449;
function retrieveAllChilds($id = null, $childs = null) {
$category = Mage::getModel('catalog/category')->load($id);
$subCategory = $category->getResource()->getChildren($category, true);
foreach ($subCategory as $categoryID)
{
$sCategory = Mage::getModel('catalog/category')->load($categoryID);
//$catnames = array();
//$category_ids = array();
foreach ($sCategory->getParentCategories() as $parent) {
//$catnames[] = $parent->getName();
//array_push($category_ids,$parent->getName());
$category_ids[$parent->getId()] = $parent->getName();
}
//echo implode('->',$catnames);
//echo '<br>';
/*echo "<pre>";
print_r($category_ids);*/
}
return $category_ids;
}
$dd = retrieveAllChilds(12449);
echo "<pre>";
print_r($dd);