To make decent excerpts, I needed something that stripped out all tags first and then limited the remaining words, all in one fell swoop, so I combined those functions into one plugin. Rick Ellis originally wrote Word Limit, then Vik Rubenfeld modified that into Word Limit Plus. I took Vik’s modification and added some HTML stripping for your eexcerpting pleasure.
For some background on this plugin, you can review these threads:
Autogenerating an excerpt when a summary doesn’t exist Definitive answer on Filter_HTML status, update or alternative, please
USAGE: Wrap anything you want to be processed between the tag pairs. Works exactly like word_limit_plus, but strips tags.
{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='{title_permalink=news/item}'>MORE...</a>"}
text you want processed
{/exp:eexcerpt}
REFERENCE:
if_exceeds - Text will be truncated if it is greater than this number of words. This parameter must be included.
stop_after - Text greater than the number of words contained in the if_exceeds parameter, will be truncated to the word length stored in the stop_after parameter. This parameter must be included. Must be less than the number of words in the if_exceeds parameter.
the_link - Optional. A link back to the original article.
The download is now over at its designated page at masugadesign.com: http://www.masugadesign.com/the-lab/scripts/eexcerpt/
Great. Thank you! You can see it in action in the left “News” column at branchenwissen.info.
Mdesign, do you see any chance to add an parameter/function to handle line breaks/paragraph so that they are more or less preserved? On a fast glance, it seems the preg_replace() uses a clever regex to filter out all tags, so one would perhaps replace br and opening p tags with some marker, filter all remaining tags and then replace the marker with br / tags? But I don’t want to mess with your code, I just would like to see an option to have the layout of the excerpt somewhat preserved but tags stripped to guarantee consistent HTML coding.
-Markus
Great. Thank you! You can see it in action in the left “News” column at branchenwissen.info. Mdesign, do you see any chance to add an parameter/function to handle line breaks/paragraph so that they are more or less preserved?
Ausgezeichnet! Gesundheit!
I didn’t want to open a big can of worms with this plugin by introducing parameters. I had a pretty specific need - which I find repeating iteself on numerous sites I work on - which is real basic excerpts with no tags in them. I really only intended this to be used with a sentence, or maybe a few sentences. Heck, all I did was take an existing plugin and throw some HTML stripping in there first. I think it would be pretty easy to keep line breaks intact, though.
Hmm, you might be on to something there though. First go through and replace with [p] (or something), then go through and wipe out tags, then replace [p] with . Is that what you were thinking?
Yes, something like this - just that I would perhaps use some either low or high ascii character as the “marker”/replacement for , and that most likely in the text processed will not be used (perhaps bell, 0x07, or something like that). Reason is this would count one character, whereas [p] would count three (so, [p] could perhaps truncated to [p or [ afterwards). Then use the preg_replace, truncating and so on as your plugin already does - and in a last step, replace the marker with or
.
Of course, it would need a parameter because for most cases the current usage is great, just to truncate longer news the line/paragraph breaks would be nice to have.
-Markus
Markus - I just came upon the need to preserve line breaks myself. I think I’ll look at updating this plugin to preserve those if possible - when I get a spare moment 😊 .
As you can see, we were having a discussion about that over on this thread.
Looks like a very nice upgrade! I’ll try it out. I second the request for choosing characters or words. Using characters gives you a little more control over the space the excerpt will fill. (Some posts use more big words than others.) Why not eliminate the need for char_limit too, eh?
Thanks for the work and thanks for sharing.
Masuga - is it possible to set the link manually in:
{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='{title_permalink=news/item}'>MORE...</a>"}
I tried to change it to read:
{exp:eexcerpt if_exceeds="600" stop_after="500"
the_link="<a href='/{segment_1}/{segment_2}/{segment_3}/category/{url_title}'>MORE...</a>"}
When I did this, it totally ignored the URL.
bjs
Hmm, I thought segment variables were parsed very early on, so I’m assuming that link should work. When you say “totally ignored”, what does that mean, exactly? It returned nothing?
Could this be used for the following situation?
I’m showing weblog entries - and if an entry is shorter than X I want the whole thing to show. If it is longer than X, I want to show X words, and then have a “show entire post” link, but instead of that link taking someone to a new page, I want to use javascript and “getElementById” to show the entire post on that same page without a reload.
Any thoughts on how I could get this extension to do that? Or should I use this as a jumping point for a new extension?
Thanks!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.