Magento: Get parent category, sub-category and product count

Here is a quick and complete code to load parent category from current category page and to get sub categories of parent category along with their product count.

* If you are in any category page then load its parent category
* Else load root category; generally root category has ID = 3
if (is_object(Mage::registry('current_category'))) {
$parentCategory = Mage::getModel('catalog/category')->load(Mage::registry('current_category')->getId())->getParentCategory();
} else {
$rootCategoryId = 3;
$parentCategory = Mage::getModel('catalog/category')->load($rootCategoryId);


//$_categories = $parentCategory->getChildren();

$_categories = $parentCategory->getChildrenCategories();
$productCollection = Mage::getResourceModel('catalog/product_collection');

//$layer = Mage::getSingleton('catalog/layer');


// Displaying active categories with their product count
foreach ($_categories as $_category):
<a href="<?php echo $_category->getUrl() ?>">
<?php echo Mage::helper('core')->htmlEscape($_category->getName()) ?>
<?php echo '('.$_category->getProductCount().')'; ?>
<br />


Hope it helps. Enjoy..........:)