如何使用Magento中的getThumbnailUrl()从类别中显示缩略图

我试图做这项工作,但没有运气,基本上我需要在内容块上显示主菜单类别,我做了,但现在我需要在内容块中显示类别名称旁边的缩略图类别。 我在app / desing / fronend / default / THEME / template / catalog / navigation / category_listing.php中创建了一个新的自定义模块,如下所示:

    getStoreCategories() as $_category): ?>
    <a href="https://stackoverflow.com/questions/13133228/how-to-display-thumbnail-from-category-using-getthumbnailurl-in-magento/getCategoryUrl($_category) ?>"isCategoryActive($_category)): ?> class="active">https://stackoverflow.com/questions/13133228/how-to-display-thumbnail-from-category-using-getthumbnailurl-in-magento/htmlEscape($_category->getName()) ?> <img src="https://stackoverflow.com/questions/13133228/how-to-display-thumbnail-from-category-using-getthumbnailurl-in-magento/getThumbnailUrl() ?>" width="100" height="100" style="background:red; height: 100px; width: 100px; display: block" alt="https://stackoverflow.com/questions/13133228/how-to-display-thumbnail-from-category-using-getthumbnailurl-in-magento/htmlEscape($_category->getName()) ?>" />
decorateDataList('narrow-by-list')

然后我将其添加到app / code / core / Mage / Catalog / model / Categorie.php

  public function getThumbnailUrl() { $url = false; if ($image = $this->getThumbnail()) { $url = Mage::getBaseUrl('media').'catalog/category/'.$image; } return $url; } 

任何想法为什么不拉动和显示图像? 我已经使用管理面板添加到类别中,清除了缓存并刷新了数据,任何想法?

Magento和Firebug

使用以下function显示类别缩略图图像

  public function getThumbnailImageUrl() { $url = false; if ($image = $this->getThumbnail()) { $url = Mage::getBaseUrl('media').'catalog/category/'.$image; } return $url; } 

然后,使用任何类别:

$ _imageUrl = $这 – > getCurrentCategory() – > getThumbnailImageUrl()

你可以得到缩略图。

请参阅此文章http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/

无需更改app / code / local / Mage / Catalog / Model / Category.php

它可以通过这些代码轻松完成…试试这个……它的作品

 $child= Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); $imageSrc = Mage::getModel('catalog/category')->load($child)->getThumbnail(); $ThumbnailUrl = Mage::getBaseUrl('media').'catalog/category/'.$imageSrc; echo ""; 

这是我在Magento 1.7.0.2上运行的解决方案

创建sub-categories.phtml文件

 Location: app/design/fronend/YOUR-THEME/default/template/catalog/navigation/sub-categories.phtml 

记下从哪里拉缩略图。 您需要在www.yourwebsitenamehere.com下面添加您网站的绝对路径。

sub-categories.phtml文件内容:

 
getCurrentCategory() ?> getCurrentChildCategories() ?> count()): ?> getIsActive()): $cur_category = Mage::getModel('catalog/category')->load($_category->getId()); $layer = Mage::getSingleton('catalog/layer'); $layer->setCurrentCategory($cur_category); $catName = $this->getCurrentCategory()->getName(); if($_imageUrl = !$this->getCurrentCategory()->getThumbnailImageUrl()): ?> getCurrentCategory()->getThumbnailImageUrl()): ?> setCurrentCategory($_maincategorylisting); ?>

创建一个静态块。
1.块标题:子类别列表
2.标识符:子类别
3.内容: {{block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"}}

创建Category.php文件
app/code/core/Mage/Catalog/Model/Category.php复制到app/code/local/Mage/Catalog/Model/Category.php 。 复制后,编辑文件。

进入文件后,查看第491行附近。查找:

 public function getImageUrl() { $url = false; if ($image = $this->getImage()) { $url = Mage::getBaseUrl('media').'catalog/category/'.$image; } return $url; } 

粘贴后:

 /** * Retrieve thumbnail image URL * * @return string */ public function getThumbnailImageUrl($fullpath = false) { $url = false; if ($image = $this->getThumbnail()) { if ($fullpath == true) { $url = Mage::getBaseUrl('media').'catalog/category/'.$image; } else { $url = $image; } } return $url; } 

后端Magento。
1.选择目录>管理类别。
2.创建或编辑将显示子类别缩略图的主类别。
3.在显示设置选项卡下
4.显示模式:仅限静态块
5. CMS Block:子类别列表
6.主持人:不
7.缩略图图像:选择您的文件

如果您没有看到您的编辑,请确保刷新您的Magento缓存。