0

On my category pages I want to display the product description under the product if it belongs to a specific category. This is what I've tried:

<?php
    $catdesc=true;
    $categoryId = $_product->getCategoryId();
    $category = Mage::getModel('catalog/product')->load($categoryId);
    if($category->getCatdesc()==428){
        $catdesc=true;
        break;
}
?>

<?php if($catdesc): ?>
    <span><?php echo $_product->getDescription(); ?></span>
<?php endif; ?>

It get's the product description alright, however for any product- whether it belongs to the specific category or not. Any ideas what I'm doing wrong?

6
  • You want to compare with category id or category description ?
    – Keyur Shah
    May 9 '17 at 13:42
  • category id and if it matches echo the product description
    – user52738
    May 9 '17 at 13:42
  • try with my below answer
    – Keyur Shah
    May 9 '17 at 13:51
  • yeah tried it, doesn't echo the product description at all now
    – user52738
    May 9 '17 at 13:52
  • may be you should compare with correct category, because code seems correct for me
    – Keyur Shah
    May 9 '17 at 14:38
0
<?php
    $catdesc=false;
    $_product = Mage::getModel('catalog/product')->load($productId);
    if(in_array(428, $_product->getCategoryIds()))
    {
        $catdesc=true;
        break;
    }
?>

<?php if($catdesc): ?>
    <span><?php echo $_product->getDescription(); ?></span>
<?php endif; ?>
1
  • hm doesn't seem to work- doesn't show the product description at all now
    – user52738
    May 9 '17 at 13:40
0

<?php $_product = Mage::getModel('catalog/product')->load($productId); ?>

<?php if(in_array(428, $_product->getCategoryIds())): ?>
    <span><?php echo $_product->getDescription(); ?></span>
<?php endif; ?>
0

You can do the job with this two line:

<?php
if(in_array(428, $_product->getCategoryIds())){
    echo "<span>" . $_product->getDescription() . "</span>";
}
?>

Probably the code of the other guys does not work because they have redeclared $ _product.

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.