Posts Tagged ‘ category ’

Category listing alphabetically in magento

<?php
$cats = Mage::getModel('catalog/category')->load(7)->getChildren();
$catIds = explode(',',$cats);
?>
<ul>
<?php foreach($catIds as $catId): ?>
<li>
<?php
$category = Mage::getModel('catalog/category')->load($catId);
echo '<a href="' . $category->getUrl() . '">';
echo $category->getName() . '</a>';
?>
</li>
<?php endforeach; ?>
</ul>

for more info visit mage-people

Advertisements

How to get all Sub-category list by a main category Id in magento..


<?php
$category = Mage::getModel('catalog/category')->load(7); // 7 is the ID of Main Category
$subcategory = $category->getAllChildren(true);
array_shift($subcategory);
if($subcategory!=null)
{

foreach ($subcategory as $sub)
{
$sub1 = Mage::getModel('catalog/category')->load( $sub);?>
<a href="<?php echo $sub1->getUrl();?>"><span>
<?php echo $sub1->getName();

}?>
<?php }?>

for more maento tutorial visit: http://blog.free-extension.com/

Advertisements