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[$i] ." ";
}
return $str_s;
} else {
return $str;
}
} else {
return $str;
}
}
[/code]
2. pass the string with word limit like:
[code language="php"]
<?php $shortContent = strip_tags($post->getShortContent()); ?>
<?php $shortContentLimited = Mage::helper('blog')->word_limiter($shortContent,34); ?>
![]()
0 Comments