![](/img/trans.png)
[英]How to get access to custom Image Attribute in list.phtml in Magento
[英]How can I get custom Magento attributes in list.phtml?
如何在Magento(版本1.4)产品类别列表(在list.phtml
)中获得自定义属性?
我正在尝试通过添加来编辑catalog.xml
<action method="addAttribute"><code>format</code></action>
并在list.phtml
<?php echo $_product->getAttributeText('format'); ?>
要么
<?php echo $_product->getFormat(); ?>
但这是行不通的。 如何才能做到这一点?
它工作正常,只需将此代码放在list.phtml或view.phtml文件中所需的位置即可。
$attribute = $_product->getResource()->getAttribute('unit');
if ($attribute){
echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}
通过$_product->getAttributes()
加载属性
http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Model_Product.html#getAttributes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.