get sub categories of specific category
<?php
$children = Mage::getModel('catalog/category')->getCategories(10);
foreach ($children as $category) {
echo $category->getName();
}
?>
------------------------------------------------------------------------------
get child category of every current category
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$currentCategoryId= $_category->getId();
$children = Mage::getModel('catalog/category')->getCategories($currentCategoryId);
foreach ($children as $category)
{
echo $category->getName(); // will return category name
echo $category->getRequestPath(); // will return category URL
}
?>
------------------------------------------------------------------------------
<?php
$parentCategoryId = 107;
$cat = Mage::getModel('catalog/category')->load($parentCategoryId);
$subcats = $cat->getChildren();
// Get 1 Level sub category of Parent category
foreach(explode(',',$subcats) as $subCatid)
{
$_category = Mage::getModel('catalog/category')->load($subCatid);
if($_category->getIsActive()) {
echo '<ul><a href="'.$_category->getURL().'"
title="View the products for the "'.$_category->getName().'" category">'.$_category->getName().'</a>';
echo '</ul>';
}
}
?>
------------------------------------------------------------------------------
<?php
$children = Mage::getModel('catalog/category')->load('10')->getChildrenCategories();
foreach ($children as $category):
$category = Mage::getModel('catalog/category')->load($category->getId());
echo '<li><a href="' . $category->getUrl() . '">' . $category->getName() . '</a></li>';
endforeach;
?>
-------------------------------------------------------------------------------
<?php
$root = Mage::getModel('catalog/category')->load(13);
$subCat = explode(',',$root->getChildren());
$collection = $root
->getCollection()
->addAttributeToSelect("*")
->addFieldToFilter("entity_id", array("in", $subCat) );
foreach($collection as $catname){
echo $catname->getName();
}
?>
No comments:
Post a Comment