“I work for Erskine Design in Nottingham. Which is nice. You've got choices, you can visit my homepage, take a look at the available downloads or view the blog archives. Please contact me whenever you like. Also, why not subscribe to the RSS feed.”
The ExpressionEngine text truncator plugin has moved to a new home where it lives (or will live) among a wider range of text helper functions, with less bugs and more updates.
Download GMS Text Plugin with Truncator v1.0.0
A while ago I posted a plugin that truncated text in ExpressionEngine without breaking words - it removed html, wrapped it in a specified tag and added some optional link text on the end.
It was posted in a hurry and as ever, this resulted in it being a bit buggy and a bit tricky for me to maintain. I have decided to change direction and create a ‘text’ plugin around it that does the same job, but better, and allows for the addition of other ‘text’ helper functions in the same plugin. We’re using it at Erskine, and it seems to be working just fine.
The name of the plugin has changed so if you want to upgrade you will need to edit your templates. I will only be maintaining this version of the plugin from now on. Sorry if this causes a bit of inconvenience, but it’s for the best. Honest.
To take a block of text and display it, truncated to 100 characters (to the nearest word) with a read more link on the end, wrapped in a list item with a class of ‘summary’, you do this:
{exp:gms_text:truncate wrapper="li" wrapper_class="summary" end_url="{url_title}" end_text="Read in full ..." char_limit="100"}
{big_long_text}
{/exp:gms_text:truncate}
George ~ Thursday, Sep 25th 2008 @ 08:18:17
Thanks very much for this. A great help that the code is so well commented too. Cheers!
Yarus ~ Sunday, Nov 30th 2008 @ 00:33:49
Thanks! This plugin very useful. Till now didn’t find any bugs.