How to Get Product Attributes in Magento Frontend

Almost every store is going to require custom attributes for its products. Naturally, you are going to want to advertise some of these features on the category and product listing pages. So I’d thought I’d take the time to write a short note on how to get this done. Initially, for each product attribute which you want to use on the product page or category page, you will have tell Magento whether or not they should be made available.

To do this, find the attribute under Magento Admin -> Catalog -> Attributes -> Manage Attribute Sets. Then under frontend properties, near the bottom, you will find options for: “Visible on Product View Page on Front-end” and “Used in Product Listing”. These will allow you to display the attribute on the product page and category page respectively.

Then, when it comes to your theme design, there are a couple of ways that you can retrieve the attribute. For most you will be able to use:

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

For example, suppose you were selling computer monitors and you had a field called screen_size. You would get the product field by:

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

However, if the attribute is a dropdown box, this will only return an ID, so you will need to use another method. Luckily, it’s just as simple to remember! The getAttributeText function takes the field name as a parameter.

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

That’s it! If you cannot get it to work, double check that you have set the right scope for the attribute in admin.