如何在Magento中使用getThumbnailUrl()从类别显示缩略图 [英] how to display thumbnail from category using getThumbnailUrl() in Magento
问题描述
我正在尝试使它工作,但是没有运气,基本上我需要在内容块上显示主菜单类别,但是我确实需要,但是现在我需要在内容内类别名称旁边显示缩略图类别.堵塞.我在app/desing/fronend/default/THEME/template/catalog/navigation/category_listing.php中创建了一个新的自定义模块,如下所示:
I have bee trying to make this work but had no luck, Basically I need to display the main menu categories on the content block and I did, but now I need to display the thumbnail categorie next to the category name inside the content block. I created a new custom module inside app/desing/fronend/default/THEME/template/catalog/navigation/category_listing.php that looks like:
<div class="box layered-nav">
<div class="head">
</div>
<div class="border-creator">
<div class="narrow-by">
<dl id="narrow-by-list">
<dd>
<ol>
<?php foreach ($this->getStoreCategories() as $_category): ?>
<dt>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?>
<img src="<?php echo $_category->getThumbnailUrl() ?>" width="100" height="100" style="background:red; height: 100px; width: 100px; display: block" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
</a>
</dt>
<?php endforeach ?>
</ol>
</dd>
</dl><script type="text/javascript">decorateDataList('narrow-by-list')</script>
</div>
</div>
</div>
然后将其添加到app/code/core/Mage/Catalog/model/Categorie.php
And then I am adding this to 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;
}
任何想法为什么不拉出并显示图像?我已经使用管理面板添加到类别中,清除了缓存并刷新了数据,有什么想法吗?
Any ideas why is not pulling and displaying the image? I already added to the category using the admin panel, cleared the cache and refreshed the data, Any ideas?
推荐答案
使用以下功能显示类别缩略图
Use this below function to display category thumbnail image
public function getThumbnailImageUrl()
{
$url = false;
if ($image = $this->getThumbnail()) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
return $url;
}
然后,将其用于任何类别:
Then, using for any category :
$ _ imageUrl = $ this-> getCurrentCategory()-> getThumbnailImageUrl()
$_imageUrl=$this->getCurrentCategory()->getThumbnailImageUrl()
您可以获取缩略图.
请参阅此文章 http://www.douglasradburn.co.uk/getting- category-thumbnail-images-with-magento/
这篇关于如何在Magento中使用getThumbnailUrl()从类别显示缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!