Magento Category Thumbnail
categories, magento, thumbnails
Solution
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.
Problem
I am trying to make use of the Magento Category thumbnail, but it is not working. I've followed many tutorials online (eg http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/), and all of them make mention of the function : ``` $_category->getThumbnail() ``` which is supposed to be in the Category model. I'm running Magento 1.6 and I can't find this function anywhere. I've also downloaded 1.5 and 1.7, looked in there and it is nowhere to be found. When I run the code it gives me no errors however, just nothing is output. Here is my full code: ``` <ul id="nav"> <?php foreach ($this->getStoreCategories() as $_category): ?> <?php echo $_category->getThumbnail(); ?> <?php echo $this->drawItem($_category) ?> <?php endforeach ?> </ul> ``` (I am trying to use the thumbnail as a menu item where it is present) Got it working. The secret is you need to re-query for the FULL category data using this code: ``` Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail() ``` I followed this tutorial somewhat: http://www.h-o.nl/blog/using_category_images_in_your_magento_navigation/ for having category thumbnails in your menu. thanks T