Magento Category Thumbnail

For what it's worth, your solution works but is quite inefficient.

Using:

Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail()

will add a few hundredths, maybe even tenths of a second per category to your page's load time.

The reason for this is you've gone to the trouble of getting a model collection and getting the item within it, and then you'll be adding new database calls that fetch the full data for each category. You need to simply ensure you collect the full category data in the first place.

The reason what you had before wasn't working is because the category collection wasn't told what attributes it needs to select. It was in effect just returning flat data from the catalog_category_entity table, not joined with any attribute tables.

What you need to do is probably more along these lines:

<ul id="nav">
<?php foreach ($this->getStoreCategories()->addAttributeToSelect("*") as $_category): ?>
    <?php echo $_category->getThumbnail(); ?>  
    <?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>

In fact, ideally you want to override the ->getStoreCategories() function to add the wildcard filter.

I recommend opening app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php and learning what sort of very cool collection functions have been written. Mastering EAV Collections is like a rite of passage for Magento developers. Once you do this you'll be unstoppable!

Hope this helps.


There is no need to change app/code/local/Mage/Catalog/Model/Category.php

It can be done easily through these line of code...try this...Its Works

$child= Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId();

$imageSrc = Mage::getModel('catalog/category')->load($child)->getThumbnail();

$ThumbnailUrl = Mage::getBaseUrl('media').'catalog/category/'.$imageSrc;

echo "<img src='{$ThumbnailUrl}' />";

this worked for me:

<img src="http://etienneaigner.com/shop/media/catalog/category/
     <?php echo Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail(); ?>"

     height="338px" width="338px"
     alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />