8/25/2010

How to get parent category Id in Magento

To get Parent Category Id you must know the current category Id, for that you need to write

<?php

$_cat = new Mage_Catalog_Block_Navigation();

$curent_cat = $_cat->getCurrentCategory();

$curent_cat_id = $curent_cat->getId();?>



Now you can get Parent Category Id.

write the code given below to get the Id


<?php
$parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();

echo
$parentId; // $parentId will print your current category's parent Id

?>

No comments:

Post a Comment