1. Create a function in your helper

/**
* @author: Sushant Vishwas
* @description: Limit word from any paragraph
* @params: String, Integer
* @return: String
*/
function word_limiter($str, $limit = 10) {
   $str = strip_tags($str);
   if (stripos($str, " ")) {
       $ex_str = explode(" ", $str);
       if (count($ex_str) > $limit) {
           for ($i = 0; $i < $limit; $i++) {
               $str_s.=$ex_str&#91;$i&#93; ." ";
           }
           return $str_s;
       } else {
           return $str;
       }
   } else {
       return $str;
   }
}
&#91;/code&#93;
2. pass the string with word limit like:
&#91;code language="php"&#93;
<?php $shortContent = strip_tags($post->getShortContent()); ?>
<?php $shortContentLimited = Mage::helper('blog')->word_limiter($shortContent,34); ?>


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *