Saturday, July 21, 2012

Magento - Limit Displayed Characters From Product Short Description

Magento by default showing more word in the Short Description ,But some time we want to reduce the length of Short description 

We can use this code wherever we required the Short Description should come with limit words



<?php $sdesc = $_product->getShortDescription();
$sdesc = trim($sdesc);
$limit = 40;
    if (strlen($sdesc) > $limit) {
      $sdesc = substr($sdesc, 0, strrpos(substr($sdesc, 0, $limit), ' '));
    } ?>
<?php echo $sdesc."..."; ?>

This script helps you limit characters form Product Short Description.

2 comments:

  1. Here's the code from 1.7.0.2 for list.phtml - LOOKING FOR HELP ON HOW TO ADD T HE LIMIT CHARACTER C
    productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>

    Thanks,
    Greg

    ReplyDelete
  2. you can just replace this line by

    echo $_helper->productAttribute($_product, nl2br($_product->getShortDescription()), 'short_description')

    by above code ......OR
    You can change like this

    echo $_helper->productAttribute($_product, nl2br($sdesc), 'short_description')

    Hope this will work for you

    ReplyDelete

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...