Magento: Get current and parent category

This article shows how to get category information (category name, id, description, url, etc.) of the category page you are in. Along with the information of the parent category of the currently viewed category.

Get current category


// Get current category
$currentCategory = Mage::registry('current_category');

Print current category array

<

pre>
$currentCategory = Mage::registry('current_category');
echo "

<pre>"; print_r($currentCategory->getData());

Get current category information


$currentCategory = Mage::registry('current_category');

$categoryName = $currentCategory->getName();
$categoryId = $currentCategory->getEntityId();
$categoryDescription = $currentCategory->getDescription();
$categoryUrlPath = $currentCategory->getUrlPath();
$categoryParentId = $currentCategory->getParentId(); 

Get parent category


$currentCategory = Mage::registry('current_category');
$parentCategory = Mage::getModel('catalog/category')->load($currentCategory->getParentId());

$parentCategoryName = $parentCategory->getName();

Hope it helps. Thanks.