cancel
Showing results for 
Search instead for 
Did you mean: 

How to display my product attribute in product list and view page

How to display my product attribute in product list and view page

Hello Magento experts. 

 

I'm not a programmer but I have to do this for my new magento store as I can't hire a programmer to do this for me. So I'd be greateful to you if I got solution for this. This should be pretty easy for you guys.

 

I have added an attribute "New" with the field "Yes/No"  Now I need to display "New" in the product list and product view pages if the value is yes. 

 

Similarly I'd like to display some custom attributes in "short description" area. For example there is an attribute called "Dimension". I want to first check if the field "Dimension" has a value or not if yes display the value with the label "Dimension", other wise don't display the label "Dimension" either. 

 

I don't know If I've explained it correct. Please help me out from this.

5 REPLIES 5

Re: How to display my product attribute in product list and view page

This is what I've used to display custom attributes in my product page

 

<?php
// check attribute exists (Where 'dimension' is the attribute code for your attribute)
if ($attribute = $this->getProduct()->getResource()->getAttribute('flooring_width')): ?>
    <?php
    // get label for the current store (in case you have multiple stores and languages)
    $_attribute_label = $attribute->getStoreLabel(Mage::app()->getStore()->getName());
    // get the attribute value (for other attributes change getDimension to getName where name is the name of your attribute );
    $_attribute_value = $this->getProduct()->getFlooringWidth();
    ?>
    <?php
    // check there is a value for the attribute
    if (isset($_attribute_value)): ?>
        <p>
            <?php echo $_attribute_label . ': ' . $_attribute_value; ?>
        </p>
    <?php endif; ?>
<?php endif; ?>

Here's a short blog post with some references for getting attributes

 

http://www.blog.plazathemes.com/archives/2372

Re: How to display my product attribute in product list and view page

Hi @Magento Customization

 

For this you need to customize the product list and product view file and add the coding according to your requirement.

  1. Product List Page : app\design\frontend\[Your Theme]\template\catalog\product\list.phtml
  2. Product View Page : app\design\frontend\[Your Theme]\template\catalog\product\view.phtml

Display the custom attribute are done like this.

echo $_product->getAttributecode()

 

Was my answer helpful? You can accept it as a solution.
175+ Professional Extensions for M1 & M2
Need a developer?Just visit Contact Us Now

Re: How to display my product attribute in product list and view page

Hello, Very thank you for your quick response. I tried the solutions you sent, I changed 

if ($attribute = $this->getProduct()->getResource()->getAttribute('flooring_width')): ?>

with getAttribute('label_new');   label_new is my custom attribute with yes/no field. And the label for it is "Mark as New"

 

please please give me the pin pointed solution. I really need your help.

Re: How to display my product attribute in product list and view page

give this a go

 

as mentioned above place this in 

 

  • Product List Page : app\design\frontend\[Your Theme]\template\catalog\product\list.phtml
  • Product View Page : app\design\frontend\[Your Theme]\template\catalog\product\view.phtm

 

 

 

<?php
// check attribute exists (Where 'dimension' is the attribute code for your attribute)
if ($attribute = $this->getProduct()->getResource()->getAttribute('new_label')): ?>
    <?php
    // get label for the current store (in case you have multiple stores and languages)
    $_attribute_label = $attribute->getStoreLabel(Mage::app()->getStore()->getName());
    // get the attribute value (for other attributes change getDimension to getName where name is the name of your attribute );
    $_attribute_value = $this->getProduct()->getNewLabel();
    ?>
    <?php
    // check there is a value for the attribute
    if (isset($_attribute_value)): ?>
        <p>
            <?php echo $_attribute_label . ': ' . $_attribute_value; ?>
        </p>
    <?php endif; ?>
<?php endif; ?>
 

 

 

 

Re: How to display my product attribute in product list and view page

You have to do some coding in order to display custom product attributes on Magento product view page. Refer to the following article as an example of displaying warranty product attribute. 

How to display custom product attributes in Magento veiw page