Magento Themes and Magento Extensions

How to get custom attributes value in Magento Frontend

Share

In Magento, you can create unlimited number of custom attributes to show different type of information about your product. These attributes can be different type as Text Field, Text Area, Date, Yes/No, Multiple Select, Dropdown, Price, Gallery, Media Image etc. Sometimes you need to get these attributes value to show in different places. There are different way to get different type of attributes.

you can get almost type of attribute value by using the following code:

  1. <?php
  2. echo $_product->getAttributeName();
  3. ?>

For example, suppose you are selling computer monitor in your web store and you created a attribute by using ‘screen_resolution‘ as its attribute code. Then You can get this attribute value by using the following code:

  1. <?php
  2. echo $_product->getScreenResolution();
  3. ?>

If it not work you can also try following code:

  1. <?php
  2. echo $this->htmlEscape($_product->getData(‘screen_resolution’));
  3. ?>

If you want to get any “Dropdown or a Multiple Select” type attribute’s value, then you should use following code to to get their value:

  1. <?php
  2. echo $_product->getAttributeText(‘screen_resolution’);
  3. ?>

Here i used screen_resolution which is my attribute code. You must use your attribute code.

Note: Make sure your attribute field “Visible on Product View Page on Front-end” is set asYes. otherwise that attribute value don’t show on forntend.

Comments are closed.