help to implement code ...
Posted: Mon Jul 26, 2010 8:05 pm
Hi!
I got a shortcode (code that can be called elsewhere on the page) om my webpage that looks like this:
This calls a text from the mysql.
But 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 tried to implement this code into the shortcode above but cant succed. But Im not very good in coding.
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
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