Skip to content

Get product attribute value on category page – Magento2

We want to load the product attribute value on the category page, of all attributes with a value “Yes” of label “is_featured”. We create the following code in the list.phtml, but this really slows down the category list page.

Is there a better/faster way to load these product values?

<?php $attributes = $_product->getAttributes();
foreach($attributes as $a)
{
    if ($a->getData('is_featured') && $a->getFrontend()->getValue($_product) != NULL){
    echo '<li><span class="">' . $a->getFrontend()->getValue($_product). '</span></li>';
    }
}
?>