Magento: Get category name and url from product
$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->getCategoryUrl() ?>"><?php echo $category->getName() ?></a><br/>
<?php
}
?>
Related posts:
- Magento: How to filter product collection using 2 or more category filters?
- Magento 1.4: No products displayed in category listing
- Magento: Get sub categories and product count
- Magento: Get current and parent category
- Magento: Adding category attributes
- Magento: Get parent id of simple product associated to configurable product
- Magento: Sort latest product by ‘created date’ and ‘new from date’
- Magento: Get Product Collection by Type
- Magento: How to get all associated children product of a configurable product?
- Magento: Get Bestselling products by category and date time
