I got a shortcode (code that can be called elsewhere on the page) om my webpage that looks like this:
Code: Select all
SC_BEGIN NEWSBODY2
global $tp;
$news_item = getcachedvars('current_news_item');
$news_body = $tp -> toHTML($news_item['news_body']);
return $news_body;
SC_ENDBut I want to edit this code so if the text is more than say 3 words long it will return with three dots like this:
I found a code that could achieve this:Word1 word2 word3 …
Code: Select all
$threshold_length = 3; // 3 words max
$phrase = 'word1 word2 word3 word4'; // populate this with the text you want to display
$abody = str_word_count($phrase,2);
if(count($abody) >= $threshold_length){ // gotta cut
$tbody = array_keys($abody);
echo '' . substr($phrase,0,$tbody[$threshold_length]) . '... ';
} else { // put the whole thing
echo ' . $phrase . ';
}Any help with solution would be very much apreciated.
So that the code just calls say the first three words in the mysql
Thanks!
/ P