将类别图像设为链接 [英] Making Category Image a link
问题描述
是否可以将您在常规信息"标签中设置的主要类别图片制作为链接?
is is possible to have the main category image that you set in the General Information tab made into a link?
它呈现为:
<img src="http://www.example.com/media/catalog/category/example.jpg" alt="Example" title="Example" class="category-image" />
也许可以扩展此功能?拥有无法点击的主横幅只是感觉不对...
There is perhaps an extension to do this? It just doesn't feel right to have a main banner that is not clickable...
推荐答案
没有一个固定的答案,但是这就是我们在Magento 1.7.0.2中能够做到的方式:
There isn't a set answer , but here was how we were able to do it in Magento 1.7.0.2:
在文件app/design/frontend/base/default/template/catalog/category/view.phtml中,有以下几行添加了图像:
In file app/design/frontend/base/default/template/catalog/category/view.phtml there are these lines that add the image:
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this- >htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /> </p>';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
这基本上是说:如果有图像-创建必要的HTML来显示它.
This basically says: if there is an image - create the necessary HTML to display it.
您可以重新创建这些相同的行,并添加一个if语句:
You can recreate these same lines and add an if-statement:
if ($_imgUrl = $_category->getImageUrl()) {
//Add this, which reads: if the following text exists in the file name of the category image then create html with a link for that specific text
if(substr($_imgUrl,-20)=="some-systematic-identification-text"){
$_imgHtml = '<p class="category-image"><a href="http://www.MY_SITE_URL.com" target="_blank"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></a></p>';
}
//Add this to check for more text
else if(substr($_imgUrl,-20)=="some-OTHER-systematic-identification-text"){
$_imgHtml = '<p class="category-image"><a href="http://www.MY_SITE_URL.com" target="_blank"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></a></p>';
}
//Otherwise - just add the standard html that was there before we made changes
else{$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';}
//Part of if-category image - if statement
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}
您可以将这些行复制并粘贴到我在本文顶部的4行中,然后根据需要进行修改,以识别您的文件名何时已显示为类别图像,并创建了适当的链接,该链接在出现时会弹出点击.
You can copy and paste these lines over the 4 I put at the top of this post and then modify as needed to identify when your file-name has been displayed as a category image and to create the appropriate link that pops out when clicked.
这篇关于将类别图像设为链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!