我试图让这项工作没有运气,基本上我需要在内容块上显示主菜单类别而且我做了,但现在我需要在内容中显示类别名称旁边的缩略图类别块。我在app / desing / fronend / default / THEME / template / catalog / navigation / category_listing.php中创建了一个新的自定义模块,如下所示:
<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
public function getThumbnailUrl()
{
$url = false;
if ($image = $this->getThumbnail()) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
return $url;
}
任何想法为什么不拉动和显示图像?我已经使用管理面板添加到类别中,清除了缓存并刷新了数据,任何想法?
答案 0 :(得分:5)
使用以下功能显示类别缩略图
public function getThumbnailImageUrl()
{
$url = false;
if ($image = $this->getThumbnail()) {
$url = Mage::getBaseUrl('media').'catalog/category/'.$image;
}
return $url;
}
然后,用于任何类别:
$ _ IMAGEURL = $这 - &GT; getCurrentCategory() - &GT; getThumbnailImageUrl()
你可以获得缩略图。
参考这篇文章 http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/
答案 1 :(得分:0)
这是我在Magento 1.7.0.2上工作的解决方案
创建子类别.phtml文件
Location: app/design/fronend/YOUR-THEME/default/template/catalog/navigation/sub-categories.phtml
记下从哪里拉缩略图。您需要在www.yourwebsitenamehere.com
下方添加网站的绝对路径。
sub-categories.phtml文件内容:
<div id="categories">
<?php $_maincategorylisting = $this->getCurrentCategory() ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php if($_categories->count()): ?>
<? foreach($_categories as $_category): ?>
<? if($_category->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()):
?>
<?php /* Default subcategory jpg if no image exists */ ?>
<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<img src="<?php echo $this->getSkinUrl('images/subcategory-default.jpg') ?>">
</a>
</div>
<div>
<p>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"> <?php echo $catName ?></a>
</p>
</div>
</div>
<? endif ?>
<? if($_imageUrl = $this->getCurrentCategory()->getThumbnailImageUrl()): ?>
<?php /* Displays the subcategory image */ ?>
<div class="category-box">
<div class="category-image-box">
<a href="<?php echo $this->getCategoryUrl($_category) ?>">
<img src="http://www.yourwebsitenamehere.com/media/catalog/category/<?php echo $_imageUrl ?>">
</a>
</div>
<div>
<p>
<a href="<?php echo $this->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?></a>
</p>
</div>
</div>
<? endif; endif; ?>
<? endforeach ?>
<?php $layer->setCurrentCategory($_maincategorylisting); ?>
<? endif; ?>
</div>
创建静态区块。
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.选择目录&gt;管理类别。
2.创建或编辑将显示子类别缩略图的主类别
3.在显示设置选项卡下
4.显示模式:仅静态块
5. CMS块:子类别列表
6.锚点:没有
7.缩略图图像:选择文件
如果您没有看到您的编辑,请确保刷新您的Magento缓存。
答案 2 :(得分:0)
无需更改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 "<img src='{$ThumbnailUrl}' />";