Sometimes we need to get all Magento categories name with URL of a product. Below code will get you all the categories with URL of product.Product can be shown under more than one category, so you may get more than one category ID.
First Method:-
$categoryCollection = $_product->getCategoryCollection(); foreach($categoryCollection as $category){ print_r($category->getData()); //echo $category->getName(); //echo $category->getUrl(); }
Second Method:- This is a more better way than the above code for programmatically.
$categoryIds = $_product->getCategoryIds(); $categoryCollection = Mage::getResourceModel('catalog/category_collection') //->addAttributeToSelect('name') //->addAttributeToSelect('url') ->addAttributeToSelect('*') ->addAttributeToFilter('entity_id', $categoryIds) ->addIsActiveFilter(); foreach($categoryCollection as $category){ print_r($category->getData()); //echo $category->getName(); //echo $category->getUrl(); }
Hope this helps. Thanks.
Toys have always played a crucial role in childhood, offering fun, learning, and creativity. Whether it's the joy of writing…
Toys are not just for entertainment—they shape childhood, enhancing creativity, learning, and motor skills. Whether it’s a comforting silicone night…
Toys are more than just playthings; they are a gateway to imagination, learning, and childhood joy. Whether it's a soft…
Toys have always played a crucial role in childhood, fueling imagination, creativity, and learning. Whether you're looking for educational playsets,…
Toys are an essential part of childhood, shaping creativity, learning, and fun-filled memories. Whether it’s the soft embrace of plush…
Toys are a gateway to imagination, creativity, and learning. Whether it’s a child’s first plush toy, a set of engaging…