Magento 1 – Get Category Thumbnail Image and Text Within Product Pages

categorymagento-1

We'd like to use the category thumbnail and text as brand info to show the logo and description on the product page. How can I get these information on the product page?

I'm working in:
…/template/catalog/product/view.phtml

Best Answer

This approach didn't work for me because:

A product can be in several categories, so when you route to the product directly, it doesn't know the category. It's easy if you don't put products in more categories but more complex if you do.

I solved the problem with this answer: https://stackoverflow.com/questions/15735324/get-a-products-parent-category-even-if-it-is-accessed-directly

Here is my code to get the thumbnail image and description text even if a product is in more than one category (hope this helps others):

        <?php
            //load all categories where the product exists
            $cat = $_product->getCategoryCollection()->addAttributeToSelect('*');
            foreach($cat as $category){
                //check if the categorie in the array has a thumbnail and desc. text
                if($category->getThumbnail() && $category->getDescription()){
                    echo '<div class="cd-brand-logo"><img src="' . Mage::getBaseUrl('media').'catalog/category/' . $category->getThumbnail() .'" alt="' . $category->getName() . ' logo"></div>';
                    echo '<p>' . $category->getDescription() . '</p>';
                    // exit the loop if success
                    break; 
                }
                else{
                    echo '<p>Thumbnail or description is missing here.</p>';
                }
            }
        ?>
Related Topic