i have created custom category attribute now i want to get the attribute value on list.phtml page i can i achieve this in magento2.

<?php if($category->getColThreeCategory()): ?>
        <ol class="grid-product-type products list items product-items col-3-wizard">
    <?php else: ?>
            <ol class="grid-product-type products list items product-items">
        <?php endif; ?>

First you need to create category custom attribute with used_in_product_listing and visible_on_front set to ture

            // ...
            'used_in_product_listing' => true, // for category pages
            'visible_on_front' => true, // for frontend??
            'is_used_in_grid' => true, // for category pages
            'is_visible_in_grid' => true // for category pages

Then you can get this custom attribute value like this.

    // or
| improve this answer | |
  • i am getting error on search page? – imtiazau Sep 12 '19 at 7:05
  • Call to a member function getData() on null – imtiazau Sep 12 '19 at 7:10
  • on search page it will not work becuase search page is not current category page so $category object will not work you need to add condtion like $currentCategory = $registry->registry('current_category'); if ($currentCategory) { // Custom code } – Narayan Jat Sep 12 '19 at 7:17
  • for magento2 this code? – imtiazau Sep 12 '19 at 7:46
  • how you getting this $category->getColThreeCategory() the $category object in your code ? – Narayan Jat Sep 12 '19 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.