For what it's worth, your solution works, but is pretty inefficient.
Using:
Mage::getModel('catalog/category')->load($_category->getId())->getThumbnail()
will add a few hundredths, or maybe even tenths of a second, for each category at the time the page loads.
The reason for this is that you are faced with the problem of getting a collection of models and getting an element inside it, and then you will add new database calls that retrieve the full data for each category. You just need to ensure that you collect the full category data first.
The reason you were before didn't work, because the category collection didn't tell you which attributes she needed to choose. In fact, it simply returned flat data from the catalog_category_entity table, and was not combined with any attribute tables.
What you need to do is probably more on 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 function ->getStoreCategories()
to add a substitution filter.
I recommend opening app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php
and finding out which very interesting collection functions were written. Mastering the EAV collections is like a ritual for Magento developers. Once you do this, you will stop!
Hope this helps.
source share