search
top

Get Products categories in Magento

Hello All,

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


<?php

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

$all_cats = array();

$product_model->reset();

$_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 Responses to “Get Products categories in Magento”

  1. Ali Nawaz says:

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

  2. Rudy says:

    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 1.4.1.1

Leave a Reply

top