![](/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.