[英]Magento 1.7.0.2 List.phtml image hover
My questions is how do I assign a custom attribute as an image for the hover image in the list.phtml file. 我的问题是如何为list.phtml文件中的悬停图像分配一个自定义属性作为图像。
I have done my research and got the site to do what I want by using this code to call the image in the grid view on list.phtml 我已经完成了研究,并通过使用此代码在list.phtml的网格视图中调用图像来使站点完成我想要的工作
<a href="<?php echo $_product->getProductUrl() ?>"
title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135); ?>"
width="135" height="135"
alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"
onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135) ?>';"
onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(135) ?>';" />
</a>
This works if the hover image is assigned as the thumbnail. 如果将悬停图像指定为缩略图,则此方法有效。
My issue is that I am using this extension to import all of my products and it doesnt allow to assign a different image for base, small and thumbnail. 我的问题是我正在使用此扩展名导入我的所有产品,并且不允许为基本,小尺寸和缩略图分配不同的图像。 You have to use the same image. 您必须使用相同的图像。 ( Yes I can go in and select each image individually and select the thumbnail but this is not an options with the number of products I have) (是的,我可以进入并分别选择每个图像并选择缩略图,但这不是我拥有的产品数量的选项)
Ok so what I have done is created a custom attribute for the products called hover image, added the column to the csv file and hey presto it works - the hover image gets assigend to the Hover Image option under Images as seen here: 好的,我要做的是为称为悬停图像的产品创建了一个自定义属性,将该列添加到了csv文件中,嘿,它开始起作用了-悬停图像被提升为“图像”下的“悬停图像”选项,如下所示:
So my question is how do i edit the line of code above so it calls the new 'hover_image' attribute instead of the thumbnail. 所以我的问题是我如何编辑上面的代码行,以便它调用新的“ hover_image”属性而不是缩略图。 I have tried changing thumbnail to 'hover_image' but the site crashes. 我尝试将缩略图更改为“ hover_image”,但该网站崩溃了。
Help please, i feel so close but not quite there. 请帮助,我感觉很亲密但还不很到位。
The problem is that your attribute "hover_image" is not loaded on you category page. 问题是您的类别页面上没有加载您的属性“ hover_image”。 to change that try this: 改变尝试这个:
go to any module config xml file if you are not sure about which is best use you local.xml add these lines under the config node 如果不确定哪个最佳使用,请转到任何模块配置xml文件。local.xml在config节点下添加这些行
<config>
...
<frontend>
<product>
<collection>
<attributes>
<hover_image/>
</attributes>
</collection>
</product>
</frontend>
...
</config>
Since "hover_image" has no yet a placeholder we need to add it. 由于“ hover_image”还没有占位符,因此我们需要添加它。 go to skin/frontend/default/default/images/catalog/product/placeholder
, here you can find placeholder for the normal images copy image.jpg and rename the copy to "hover_image.jpg" 转到skin/frontend/default/default/images/catalog/product/placeholder
,在这里您可以找到普通图像副本image.jpg的占位符,并将副本重命名为“ hover_image.jpg”
After that, clear your cache. 之后,清除您的缓存。 if you are using the product flat index, reindex it. 如果您使用的是产品统一索引,请对其重新索引。 Then you should be able to use 那你应该可以使用
<?php echo $this->helper('catalog/image')
->init($_product, 'hover_image')
->resize(135) ?>
let me know if not 让我知道是否
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.