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->getUrl() ?>"><?php echo $category->getName() ?></a><br/>
    <?php
}

?>

 

来源:http://blog.chapagain.com.np/magento-get-category-name-and-url-from-product/

 

 

 

 

 

你可能感兴趣的:(agent)