Get Products categories in Magento

Hello All,

I am writing here the script to get category ids , for the given product.


$product_model = Mage::getModel('catalog/product'); //get product model        		

$all_cats = array();


$_product = $product_model->load($product_id); // $product_id is the given product id 

$all_cats = $product_model->getCategoryIds($_product); // all the categories to which this product is assigned	


Hope this is useful

3 thoughts on “Get Products categories in Magento

  1. in /app/design/frontend/PACKAGE/TEHEME/template/catalog/product/view/media.phtml
    $_helper = $this->helper(‘catalog/output’);
    $_product->getCategoryIds(); // Array

  2. Hi,

    I want to display all categories a product is added to on the product view page. If i use your code nothing happens. Can you help me with this? Using magento

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top