Magento – How to get all parent category using category Id

categorymagento-1.9

I want all parent category name using category Id

  • Main Category

    • Sub Category 1

      • Sub Category 3
      • Sub Category 4
    • Sub Category 2

      • Sub Category 5
      • Sub Category 6

Now I have id of this category Sub Category 6 Now i want all parent category name means i want this two name Sub Category 2,Main Category in frontend How to get all parent category name

Best Answer

$category = Mage::getModel('catalog/category')->load($id);

$catnames = array();
foreach ($category->getParentCategories() as $parent) {
    $catnames[] = $parent->getName();
}