$product->getCategoryIds() gives array of category ids which the product is associated to. We can loop through this array and load each category to get the category name and url.
<?php
/**
* get categories from a product
*/
$categoryIds = $product->getCategoryIds();
/**
* looping through the array of category ids
*/
foreach($categoryIds as $categoryId) {
$category = Mage::getModel('catalog/category')->load($categoryId);
?>
Category: <a href="<?php echo $category->getUrl() ?>" target="_blank" rel="external nofollow" ><?php echo $category->getName() ?></a><br/>
<?php
}
?>
來源:http://blog.chapagain.com.np/magento-get-category-name-and-url-from-product/ |