cancel
Showing results for 
Search instead for 
Did you mean: 

How to display Custom attributes on Category page?

How to display Custom attributes on Category page?

Hello,

 

I want to display Model Number (model_no)  in category pages like below.zoro.png

 

How can I achieve this?

6 REPLIES 6

Re: How to display Custom attributes on Category page?

Hi @chathuramk,

I am unable to see your screenshot. 

You can display custom product attribute on category page. 

$_getMyAttr = $_product->getResource()->getAttribute('model_no'); // attribute name

// Get Value
$attrTestValue = $_getMyAttr->getFrontend()->getValue($_product);

// Get Label
$attrTestLabel = $_getMyAttr->getStoreLabel();


Also check following property:

  • if you do want to see an attribute, go in the Magento backend and verify the attribute is setup to be Used In Product Listing

  • then, you may have to refresh the index/cache and your code will show the attribute you will have verified.

I hope it will help you!

Re: How to display Custom attributes on Category page?

hi @Vimal Kumar 

 

Please see the screenshot here > https://ibb.co/gDvyYmh

Re: How to display Custom attributes on Category page?

Hi @chathuramk,

You can edit your list.phtml file. 

in default magento : 

vendor\magento\module-catalog\view\frontend\templates\product\list.phtml

copy this file to your current theme if not exist, otherwise edit your theme list.phtml file.

you can also check your current phtml file using template path hint setting.
https://docs.magento.com/m2/ce/user_guide/system/template-path-hints.html 

Add following code in this where products are showing in loop. 

$_getMyAttr = $_product->getResource()->getAttribute('model_no'); // attribute name

// Get Value
$attrTestValue = $_getMyAttr->getFrontend()->getValue($_product);

// Get Label
$attrTestLabel = $_getMyAttr->getStoreLabel();

Also check following property:

  • if you do want to see an attribute, go in the Magento backend and verify the attribute is setup to be Used In Product Listing

  • then, you may have to refresh the index/cache and your code will show the attribute you will have verified.

I hope it will help you!

Re: How to display Custom attributes on Category page?

Hi @Vimal Kumar 

 

I added code in list.phtml as below. (see screenshot link)

https://ibb.co/VMgzy28

 

After that my category page is empty. (see screenshot link)

https://ibb.co/ZNcq19R

 

Attribute visible in product listing enabled.

Re: How to display Custom attributes on Category page?

@chathuramk 

What is your attribute type?

If text then use the following code:

$_product->getData('model_part');

Re: How to display Custom attributes on Category page?

Did this work? I want to display attributes on category page as well. Magento 2