简体   繁体   English

Magento:如何通过标签获取图像?

[英]Magento: How to get an image by label?

I have another question for you guys :P 我还有另一个问题:P

On the product grid view i want to change the image when you hover over it with your mouse. 在产品网格视图上,我想用鼠标悬停在图像上时更改图像。 The image i want to switch it too should have a labelname of 'back'. 我想要切换它的图像应该有一个标签名为'后'。

I almost have it..:P 我几乎拥有它......:P

When i use this code in media.phtml: 当我在media.phtml中使用此代码时:

<?php $imageByLabel = $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'back');?>
<?php echo $this->helper('catalog/image')->init($_product, 'image', $label->getFile())->resize(235, 350);?>

It returns something like this: http://www.mywebsite.com/product/images/image1 When i use this in the source attribute of my image it displays the correct image. 它返回如下内容: http//www.mywebsite.com/product/images/image1当我在我的图像的source属性中使用它时,它显示正确的图像。

But when i use this code in the catalog/product/list.phtml i get the following error: 但是当我在catalog / product / list.phtml中使用此代码时,我收到以下错误:

Fatal error: Call to a member function getItemByColumnValue() on a non-object in C:\\Development\\FabriqMagento\\app\\design\\frontend\\default\\fabriq\\template\\catalog\\product\\list.phtml on line 95 致命错误:在第95行的C:\\ Development \\ FabriqMagento \\ app \\ design \\ frontend \\ default \\ fabriq \\ template \\ catalog \\ product \\ list.phtml中的非对象上调用成员函数getItemByColumnValue()

PS: line 95 is the following line: PS:第95行是以下行:

<?php $imageByLabel = $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'back');?>

Any help is appreciated:) 任何帮助表示赞赏:)

If you review your code, $imageByLabel is not doing anything so it is not needed. 如果您查看代码, $imageByLabel没有做任何事情,因此不需要它。

Try: 尝试:

<?php echo Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->getItemByColumnValue('label','black')->getFile();  ?>

from list.phtml 来自list.phtml

For not list.phtml: 对于list.phtml:

$_item = $this->getItem();
$_product = $_item->getProduct();

@Francis Kim - method - also with resiz @Francis Kim - 方法 - 也有resiz

$_image = Mage::getModel('catalog/product')->load( $_product->getId() )->getMediaGalleryImages()->getItemByColumnValue('label','FRONTSHOP');
echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(75);

Only issue that i found is that its not working with Exclude value 我发现的唯一问题是它不能使用Exclude值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM