this is my code:
$product_id = Mage::registry('current_product')->getId();
$product = Mage::getModel('catalog/product')->load($product_id);
$cats = $product->getCategoryIds();
foreach ($cats as $category_id) {
$parentId = Mage::getModel('catalog/category')->load($category_id)->getParentId();
$parent = Mage::getModel('catalog/category')->load($parentId);
echo $parent->getName(); // getting the parent category, but not the base category(first level)
$_cat = Mage::getModel('catalog/category')->load($category_id);
echo $_cat->getName(); // getting the category
}
I have multiple level of categories. I want to get the first level of category using one of the subcategories id. How can i do that ?