English 中文(简体)
Magento category Thumbnail
原标题:Magento Category Thumbnail

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.

我的全文如下:

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

(我 t惜把th子当成一面的菜单)


它工作。 秘密是,你需要重新排列使用该代码的“FUL”类数据:

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

我略感遵循这一理论:

http://www.h-o.nl/blog/using_ category_images_in_your_magento_navigation/

for having category thumbnails in your menu.

thanks T

最佳回答

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

使用:

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

在您的网页负荷时间上,将增加几百个,甚至可能是每类第二位数的十几个。

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.

你以前曾做过的工作的原因是,收集的类别没有告诉它需要选择什么属性。 实际上,它只是从数据表上退回数据,而没有加入任何特性表。

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>

事实上,理想的是,你想要超越<代码>->getStore()的功能,增加野心过滤器。

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.

问题回答

无需修改配对/编码/当地/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}  />";

这为我工作:

<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()) ?>" />

只是到了这一答案。 然而,在后来的1.57+版中,没有必要在法典中增加间接费用,因此,你可以通过汇辑添加更多的标准(和习俗)特性。 如果你检查Mage/Catalog/etc/config.xml,你将在通知中通知:没有:

   <category>
        <collection>
            <attributes>
                <name/>
                <url_key/>
                <is_active/>
            </attributes>
        </collection>
    </category>

因此,你可以建立自己的单元,并增加更多的外在特征:

    <category>
        <collection>
            <attributes>
                <thumbnail/>
                <image/>
            </attributes>
        </collection>
    </category>

这些材料将添加到你的类别收集中。





相关问题
How to access thumbnail cache of vista and 7 using c#

I wanted to access the thumb cache of vista and 7 to be used in my ImageList. I know how to do it in XP by means of the thumbs.db files, but in vista and 7 the thumbs.db is not present so how will i ...

User-Defined Thumnails for Django Project?

I m putting together a Web site that makes heavy use of images. Those images need to be thumbnailed at various sizes to fit different templates. I m aware of solutions like sorl-thumbnail, which ...

How to thumbnail faster in c#

I m trying to thumb an image as fast as possible regardless of the usage of resources to be used in my ImageList and listview and this is currently how i m doing it but it seems to be slow: public ...

CGImage create thumbnail image with desired size

I want to create the thumbnail using the CG. It creates the thumbnails. Here i want to have the thumbnail with the size 1024 (with aspect ratio.) Is it possible to get the desired size thumbnail ...

IThumbnailProvider and IInitializeWithItem

I am trying to develop an IThumbnailProvider for use in Windows 7. Since this particular thumbnail would also be dependant on some other files in the same directory, I need to use something other than ...

热门标签