![]()
Adding custom attributes to your product view is very easy. Adding them to the product listing (category pages) is much more difficult. You’ll need to create a custom module for that. In this post though, I’ll only be showing you how to add attributes to the product view page.
If it is a text field (textbox or textarea), this is all you have to do:
1 | <?php echo $_product->getAttributeName() ?> |
There is one thing different here though. If your Attribute Code is “shirt_size”, then you would use getShirtSize(). Remove the underscores and capitalize the first letter of each word. It is picky that way. if you use getshirtsize(), it won’t work.
If you are using a dropdown or a multiple select, you have to call it a little differently:
1 | <?php echo $_product->getAttributeText('shirt_size') ?> |
This method requires the actual Attribute Code. If you are displaying the value from a dropdown, you’ll get exactly what you need with this call. If you are wanting to display the values from a multiple select, it will return an array.

What file is this in?
Astronomad,
/app/design/frontend/default/default/template/catalog/product/view.phtml
I need to show select box of my new attributes(color/size). that i did by using above method.
Now i need to show the attribute in shopping cart and also it must be shown in order details page how can i do that?
Thanks so much for this great info. I used this to show an attribute on view.phtml that is a link. I see the link and my attribute but it is text rather than an active hyperlink. Any ideas ? Thanks for the wonderful resource Josh !
Thanks.. I was wondering why my getAttributeText wasn’t working for the text field.
and how for price fields?
Fantastic, thank you soooo much! How do people find out this stuff?
Thank you for this little snippet. It was exactly what I was looking for. Is there a list of common functions for Magento like can be found in the WordPress codex? I find the Magento wiki to be… lacking.
thank you soo much, this is exactly what I was looking for.
using magento 1.3.2.4, how to get custom attributes in the /app/design/frontend/default/default/template/catalog/product/list.phtml intead of view.phtml.
i want to show custom attributes in the product listing when people are searching for it.
i tried using $_product->getNextShipmentDate() but it returns null in list.phtml. it returns the expected value in view.phtml.
i got it.. i had to enable ‘Used in product listing’ in the attribute settings.
after enabling this, $_product->getNextShipmentDate() is not returning null anymore and showing the same value as in view.pthml.
now i need to figure out how they format the date for display.
great for product pages… however getAttributeText(”) for custom category attributes.. not so good.
The attribute I just created is a drop down for categories, now getNAMEOFATTRIBUTE() returns a 1,2 or 3 (the total number of drop down options I have) but never the value of the selected attribute option. getAttributeText(”) as you stated is for drop downs returns nothing.
Completely opposite for product pages though.
Thanks “ted”.
Information provided by you helped me a lot.
Thanks again…
“ted”?
Thank you so much for your valuable contribution
i created an attribute which is price attribute and i named it “retailprice”. I can see it in the additional information tab. How can i show it in the product list?
How to get the product cost attribute value on reports .
i need this product cost feild to be displayed on sales report and best sellers report.
report–>sales–> sales report
report–>Advanced–> bestsellers
plz help its urgent.
Any idea why this wont work on catelog->category->view.pthml when trying to call out category attributes? As I stated above, getAttributeText(‘my_attribute’) for category drop downs or multi-select wont work on category level..
Very frustrating.
OH got it!
Note to self (and others):
$categoryFull = Mage::getModel(“catalog/category”)->load($this->getCurrentCategory()->getId());
$attributes = $categoryFull->getAttributes();
echo $attributes['your_custom_attribute']->getFrontend()->getValue($categoryFull);
This will get values of custom attributes for categories!
isnt this posible in the xml files? I dont like changing the templates…
It’s great! Thank you!
muchos gracious, I’ve found this to be a very useful post!
I know this keeps getting rehashed but I’m not getting any results by using the code! I have everything set correctly from what I can tell.
Modern Theme
Magento 1.4.1.0
Cache OFF
Attribute is set to display on product page!
The attribute actually shows up in the TAB where it should. But I can’t get the data to repeat. I’ve got php skills too! It’s burning me here…
My attribute is “bsc_brand_nm” I’m using…
getBscBrandNm() ?>
Anyone see an error that my eyes are blurring on?
RBusiness – it appears that your code didn’t fully come through. I’ll email you, and if you could send me a pastebin of the code and let me know what type of attribute it is, I’ll try to help.
Josh – any updates on using this on 1.4.1.1? I can’t seem to get it to work.. I see that RBusiness had the same issue I am having.
May – Works fine for me…
Why difficult? For retrieve attributes from category page here is the code:
$_product->getResource()->getAttribute('vehicle_type')->getFrontend()->getValue($_product)vehicle_type is the attribute code
Thanks for providing this.
I noticed that if I had an attribute with ‘multiple select’ and in the admin only one option was selected it didn’t display the array.
I’ve expanded the code in that scenario: [EDIT: Sorry, the code didn't come through right...]
Thanks, very useful.
But I’m trying to call a custom attribute in the head section of my product page, and that’s not working with
getAttributeName() ?>Do you have an idea how to call an attribute in the head section?
Hans – The block that serves up the head of your page does not have access to the current product object. You’ll notice at the top of the view.phtml template, there is this line: $_product = $this->getProduct();. $this refers to the block that is loading up all of the data for the view template. I’m not sure why you’d want to get at product attributes in the head template… But, one thing you could try is Mage::registry(‘current_product’)->getData(‘attribute_code’). I haven’t tested it, but that may work…
Hi Josh, I did notice the line to load the product in view.phtml, so I allready tried putting that line in the head.phtml but that didn’t work either.
So I just tested the Mage::registry(‘current_product’)->getData(‘attribute_code’) code and that worked great, thanks again for that one!
Now I can put my own specified canonical link to the products pages.
Some times like in grouped.phtml you have to do it like this
htmlEscape($_item->getAttributeText(‘contenance’)); ?>
The attribute label doesn’t get translated when changing the store’s language.
It’s interesting because the same attribute gets translated in the more info tab
any ideas on how to solve this?
this wasn’t working for me until I removed the ‘quotes’ around shirt_size. If you’re having trouble with this in magento 1.4+, that may be your issue.
Very good article
How to display custom attrubutes in magento 1.4.1.1 ?
solution of call custom attribute
function getAttr($product_id, $attributeName) {
$product = Mage::getModel(‘catalog/product’)->load($product_id);
$attributes = $product->getAttributes();
$attributeValue = null;
if(array_key_exists($attributeName , $attributes)){
$attributesobj = $attributes["{$attributeName}"];
$attributeValue = $attributesobj->getFrontend()->getValue($product);
}
return $attributeValue;
}
Thanks Vishal. It works fine. catalog/output – to catalog/product do the trick…
Does anybody know how can I display attribute in the related product block?
Where do I add this snippet of code to display on product page? I’ve found numerous posts on other sites saying go to:
/app/design/frontend/default/default/template/catalog/product/view.phtml
But when I look at my server via FTP, I don’t have any other folders after template in that breadcrumb.
Any suggestions? I’m using 1.6 CE
Thanks!
thank you very much.
you saved me a lot of time. =)
My code looks the same; but on the front end I am seeing a number instead of the attribute; for example instead of Style: Garnet, It shows Style: 31.
Any suggestions?