I am showing a specific attribute on product page directly under short description instead of additional information section. I am able to achieve that but I want to show particular attribute only for products from a specific category. Not for all products from other categories. I need some IF statement here to show this only for specific category, for example cat ID 7. Anybody can help?

<?php echo $_product->getAttributeText('fabric') ?>

3 Answers 3



$category_id = 7;
if(in_array($category_id, $_product->getCategoryIds())){
   echo $_product->getAttributeText('fabric')
  • nope, not working, not showing any result at all.
    – LuckyB
    Aug 18, 2014 at 16:19
  • For me, I am able to get the value of attribute with the code I have in my question or maybe I am not understanding you.
    – LuckyB
    Aug 18, 2014 at 16:29
  • What is the output of print_r($_product->getCategoryIds());? Aug 18, 2014 at 16:30
  • Strange, I am getting no result for desired product, but getting cat ID perfectly for all other products.
    – LuckyB
    Aug 18, 2014 at 16:32
  • the print value in products of other categories is Array ( [0] => 10 ) and in product that I want to show, is Array ( )
    – LuckyB
    Aug 18, 2014 at 18:08

The code that worked for me is this, posting here as answer if this is needed by anyone and other codes didnt work for them.

<?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==7): ?>
<?php echo "a is a" ?>
<?php endif; ?>

In Magento-1.9, Display the custom attribute settings

Magento Admin Panel -> Catalog -> Attributes -> Manage Attributes -> Add Attribute ->

Frontend Properties -> Visible on Product View Page on Front-end here select the "Yes" option.

Once you can try this method.

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.