- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to display Custom attributes on Category page?
Hello,
I want to display Model Number (model_no) in category pages like below.
How can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to display Custom attributes on Category page?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to display Custom attributes on Category page?
Hi @Vimal Kumar
I added code in list.phtml as below. (see screenshot link)
After that my category page is empty. (see screenshot link)
Attribute visible in product listing enabled.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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');
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Re: How to display Custom attributes on Category page?
Did this work? I want to display attributes on category page as well. Magento 2