This plugin will take a block of text and only return the first line (e.g. everything before a newline/return). It’s useful for showing summaries/excerpts from blog entries or on EE search result pages where you don’t have an exceprt/summary field already setup. HTML is not stripped out either.
Usage is simply:
{exp:summary}
Text to be processed
{/exp:trim_title}An example would be as follows:
{exp:summary}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.
Suspendisse sem massa, lacinia ac auctor at, fermentum sed arcu. Quisque lobortis porta neque, ut venenatis magna feugiat vitae.
Mauris vehicula semper accumsan. Proin mollis enim nec enim adipiscing congue. Vestibulum vitae iaculis odio. Ut tincidunt, dolor quis volutpat accumsan, ante massa feugiat nisl, vitae pulvinar leo ipsum at purus.
{/exp:trim_title}What would be returned is this:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.You can also specify how many lines to return by flagging the returns parameter:
{exp:summary returns="2"}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.
Suspendisse sem massa, lacinia ac auctor at, fermentum sed arcu. Quisque lobortis porta neque, ut venenatis magna feugiat vitae.
Mauris vehicula semper accumsan. Proin mollis enim nec enim adipiscing congue. Vestibulum vitae iaculis odio. Ut tincidunt, dolor quis volutpat accumsan, ante massa feugiat nisl, vitae pulvinar leo ipsum at purus.
{/exp:summary}…will return the following:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.
Suspendisse sem massa, lacinia ac auctor at, fermentum sed arcu. Quisque lobortis porta neque, ut venenatis magna feugiat vitae.If you leave out the returns parameter, it will default to only return the first line.
You can download the latest version here:
http://ee.cwhapps.com/plugins/summary/latest.zip
@JArment: Done. Usage is as follows:
{exp:summary returns="2"}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.
Suspendisse sem massa, lacinia ac auctor at, fermentum sed arcu. Quisque lobortis porta neque, ut venenatis magna feugiat vitae.
Mauris vehicula semper accumsan. Proin mollis enim nec enim adipiscing congue. Vestibulum vitae iaculis odio. Ut tincidunt, dolor quis volutpat accumsan, ante massa feugiat nisl, vitae pulvinar leo ipsum at purus.
{/exp:summary}…will return the following:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nulla mauris, pharetra ac iaculis at, aliquet id diam.
Suspendisse sem massa, lacinia ac auctor at, fermentum sed arcu. Quisque lobortis porta neque, ut venenatis magna feugiat vitae.If you leave out the returns parameter, it will default to only return the first line.
Thanks for the awesome plugin! I am however having a problem getting it to work. When I try to call the plugin, I am getting the following error:
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: summary/pi.summary.php
Line Number: 17
Fatal error: Call to a member function fetch_param() on a non-object in /home/juser/site_system/expressionengine/third_party/summary/pi.summary.php on line 18Any ideas of what is going on here?
Hi there,
Thanks for this plugin, it looks really useful as it will save me having to bother with separate ‘summary’ and ‘body’ fields! 😊
I have one request though - is there any chance you can add a ‘skips’ or similarly named parameter that would literally skip the first x number of lines and then output the rest of the content?
I’m thinking that this could be useful on article-like pages. For example, I have a single field called ‘Content.’ In order to get my first line summary, I use your plugin around my ‘Content’ field and I will also style this line differently as it’s an introduction paragraph. Then I’ll repeat the same ‘Content’ field but my problem is that it’ll repeat the first line again. So this ‘skips’ parameter would allow me to enter a value of 1, and it’d then output the entire field contents after skipping the first line.
Also, I originally downloaded this from Devot-ee and noticed that the download link there links to the 1.0.0 version so you might want to update this for anyone who doesn’t see this forum thread.
Thanks.
Wow, this doesn’t work for me at all unfortunately. :(
After installing, my plug-in manager is all messed up. This shows up on the top of the page, looks like a PHP message:
'Summary', 'pi_version' => '1.0.1', 'pi_author' => 'Kyle Anderson', 'pi_author_url' => 'http://www.crucialwebhost.com/', 'pi_description' => 'Grabs the first line or paragraph from a block of text.', 'pi_usage' => Summary::usage() ); class Summary { var $return_data = ''; function Summary() { global $TMPL; $text = $TMPL->tagdata; $returns = $TMPL->fetch_param('returns'); if(!$returns || $returns == 1) { preg_match('/^(.*)/', $text, $matches); $this->return_data = $matches[1]; } else { $lines = preg_split('/\r\n|\r|\n/', $text, ($returns + 1)); $return = ''; for($i = 0; $i < ($returns); ++$i) { $return .= $lines[$i]; } $this->return_data = $return; } } function usage() { ob_start(); ?> This plugin will take a block of text and only return the first line (e.g. everything before a newline/return). It's useful for showing summaries/excerpts from blog entries or on EE search result pages where you don't have an exceprt/summary field already setup. HTML is not stripped out. The following will return only the first line before a return is met: {exp:summary} text you want processed {/exp:summary} If you want to return more than one line, do the following: {exp:summary returns="3"} text you want processed {/exp:summary} Which will return the first three (3) lines.Summary does not show up in the plug-in list, but it does create a second instance of another plug-in in the list.
I tried using the {exp:summary} code on my page but all it did was delete the whole design and replace it with the code above. I’m very surprised!
I’m on Build: 20100121 of 1.6.8, BTW. I’m sure it’s something odd, sounds like a great plug-in.
Jeremy
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.