我还有另一个问题:P
在产品网格视图上,我想用鼠标悬停在图像上时更改图像。 我想要切换它的图像应该有一个标签名为' back'。
我几乎拥有它......:P
当我在media.phtml中使用此代码时:
<?php $imageByLabel = $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'back');?>
<?php echo $this->helper('catalog/image')->init($_product, 'image', $label->getFile())->resize(235, 350);?>
返回如下内容:http://www.mywebsite.com/product/images/image1 当我在我的图像的source属性中使用它时,它会显示正确的图像。
但是当我在catalog / product / list.phtml中使用此代码时,我收到以下错误:
致命错误:在第95行的C:\ Development \ FabriqMagento \ app \ design \ frontend \ default \ fabriq \ template \ catalog \ product \ list.phtml中的非对象上调用成员函数getItemByColumnValue()< / p>
PS:第95行是以下行:
<?php $imageByLabel = $_product->getMediaGalleryImages()->getItemByColumnValue('label', 'back');?>
感谢任何帮助:)
答案 0 :(得分:5)
如果您查看代码,$imageByLabel
没有做任何事情,因此不需要。
尝试:
<?php echo Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages()->getItemByColumnValue('label','black')->getFile(); ?>
来自list.phtml
答案 1 :(得分:1)
不是list.phtml:
$_item = $this->getItem();
$_product = $_item->getProduct();
@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);
我发现的唯一问题是它不能使用排除值