TruncHTML Documentation
Installation:
Unzip the archive and copy the file pi.trunchtml.php into the plugins-directory inside your Expression Engine system-directory.
Usage example:
Wrap any text/html you want to be truncated inside an {exp:trunchtml}-tag-pair.
{exp:trunchtml chars="300" ending="<a href='{path=site/comments}'>read on</a>"}{body}{/exp:trunchtml}
Parameters:
chars="100"
Defaults to 500. Number of characters that are to be returned.
ending="..."
Optional. String to be added after the output.
inline="..."
Optional. This string is placed directly after the truncated text and before any closing tags. If you want the first character to be a space, use an underscore
e.g. inline=“_continue”
exact="yes"
If this is set, text will be truncated after exactly the specified number of chars. Otherwise text will be cut after a space to prevent cutting words in the middle.
threshold="X"
If this is set the text will only be truncated if it at least X characters long.
Otherwise the full text is returned.
Questions / bug reports
For general comments, brickbats & bouquets please use the form over here.Page 4 of 4 pages « First < 2 3 4
User Talk
2009-03-29 11:33
Thanks, just used this instead of word limit plus which is not html aware, however as I have not yet purchased a license I can’t post on the EE plugin forum ????
An enhancement request, would it be possible to have an option for the “please read more” link to appear before a closing ‘p’ tag rather than after it? This would make the link appear to be inline.
Now obviously your code closes all open tags at the end and deciding quite where to do it could get tricky in the general case but for well formed HTML would inserting it prior to a closing ‘p’ do the trick. I.e. in your final foreach have
if ( $tag == ‘p’ && !empty($ending) ) {
$truncate .= $ending;
$ending = “”;
}
before appending the tag. I have done this and with an inline=“_… ” (there’s an nbsp at the end of that) it seems to work just fine. Of course it is easy to break this, if there is an unclosed ‘b’ tag when $ending is inserted then $ending will also be in bold
2009-01-23 08:51
Hello, ![]()
Can You give for me some advice: How can I made more longer name in adress bar. At now, auto named adress is cuting with wp (sourse is title of my post), and some words is unfinished. You can see it trought shearing may blog
, Please.
I am form Georgia, and srry for mistakes:), my native language is Georgian
2008-11-27 22:47
Ok this is weird… when I changed to using single quotes ’ it worked but when I use the normal double quote ” it doesnt… and i mean double quote and not two of these ’
2008-11-27 22:04
I just installed truncHTML however no matter what I change the chars=“xxx” to it always limits the characters to I think 500.
Example code
{exp:trunchtml chars=“200” ending=”...”}{body}{/exp:trunchtml}
2008-10-13 09:40
Would be nice if the ending=”” works with XHTML formatting. For example:
{exp:trunchtml chars=“300” ending=”...”}{article_content}{/exp:trunchtml}
if article_content has some content here, the output would be:
some content here…
instead of: some content here…