本文介绍了如何访问Magento中list.phtml中的自定义图像属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在magento中创建一个网站.

I am creating a website in magento.

因此,我在产品中添加了新的媒体图像属性.我想为主页使用特定的图像,但是有些产品将没有该图像.

So i have added a new media image attribute to my products. I want to use a specific image for my homepage but a few products will not have this image.

因此,我创建了一个名为list-homepage.phtml的新list.phtml文件.

So i have created a new list.phtml file called list-homepage.phtml.

所以我现在在list.phtml中用于循环的产品集合中执行此操作.

so i am doing this at the moment within product collection for loop in list.phtml.

$product=Mage::getModel('catalog/product')->load($_product->getId());

我要从上方重新加载产品,然后进行测试以查看该产品是否具有新的图片属性

i am loading the product again from above, and i test to see if this product has the new image attribute

<?php if ($product->getMaleFemaleImage()){  ?>
      <img src="<?php echo $this->helper('catalog/image')->init($product, 'male_female_image')->setQuality(100)->resize($imgSize); ?>" width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'male_female_image'), null, true) ?> " />
<?php }else{ ?>
     <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->setQuality(100)->resize($imgSize); ?>" width="<?php echo $imgSize ?>" height="<?php echo $imgSize ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php }?>

这有效但是从上面可以看到,我必须再次加载产品,而我不想这样做.有什么方法可以访问我创建的male_female_image属性.

This works BUTAs you can see from above i have to load the product again and i do not want to do this. Is there any way to get access to the male_female_image attribute i have created.

推荐答案

看看@

打开app/design/frontend/default/yourtheme/layout/catalog.xml

Open app/design/frontend/default/yourtheme/layout/catalog.xml

<catalog_category_layered translate="label"><catalog_category_default translate="label">中找到下面的行

 <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
 <block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
 <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

和(添加<action method="addAttribute"> ....)

<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
add -->   <action method="addAttribute"><name>MaleFemaleImage</name></action>
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">

阅读更多@

如何添加属性到类别中的产品网格

这篇关于如何访问Magento中list.phtml中的自定义图像属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 07:15