简体   繁体   中英

How can I get custom Magento attributes in list.phtml?

How can I get custom attributes in the Magento (version 1.4) category list of products (in list.phtml )?

I am trying to edit catalog.xml by adding

<action method="addAttribute"><code>format</code></action>

and in list.phtml

<?php echo $_product->getAttributeText('format'); ?>

or

<?php echo $_product->getFormat(); ?>

But it doesn't work. How can this be done?

It works fine, just place this code to where you need in list.phtml or view.phtml file.

$attribute = $_product->getResource()->getAttribute('unit');
if ($attribute){
    echo $attribute_value = $attribute ->getFrontend()->getValue($_product);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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