Limit the number of words in excerpt without plugins...
Put the following piece of code in your templates functions.php file:
<?php
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
?>
Next, put the following piece of code in your template where you want to display the excerpt:
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
Where 25 is the number of words to display.
Put the following piece of code in your templates functions.php file:
<?php
function string_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
?>
Next, put the following piece of code in your template where you want to display the excerpt:
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,25);
?>
Where 25 is the number of words to display.
No comments:
Post a Comment