We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Summary

Development and Programming

divspace's avatar
divspace
29 posts
15 years ago
divspace's avatar divspace

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

       
russlipton's avatar
russlipton
305 posts
15 years ago
russlipton's avatar russlipton

You guys are awesome. It’s especially nice to have some ‘free’ 2.X addons …. thanks for being so generous with all your work.

       
JArment's avatar
JArment
131 posts
15 years ago
JArment's avatar JArment

This looks great. Any possibility of having a parameter to for the number of retunrs? i.e. returns=”1” would be the default, but if you want to include two paragraphs, you could do returns=”2”.

       
divspace's avatar
divspace
29 posts
15 years ago
divspace's avatar divspace

@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.

       
JArment's avatar
JArment
131 posts
15 years ago
JArment's avatar JArment

Sweetness! Thanks!

       
JmanPro's avatar
JmanPro
49 posts
15 years ago
JmanPro's avatar JmanPro

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 18

Any ideas of what is going on here?

       
divspace's avatar
divspace
29 posts
15 years ago
divspace's avatar divspace

@Jerman:

Could you please let me know what version you are using and paste the EE code? Thank you!

       
JmanPro's avatar
JmanPro
49 posts
15 years ago
JmanPro's avatar JmanPro

Sure. I am running version v2.0.1pb01 - Build: 20100121

The code is: {exp:summary}{body}{/exp:summary}

I of course tried it with sample text as well, same problem.

       
divspace's avatar
divspace
29 posts
15 years ago
divspace's avatar divspace

Thanks. This has only been tested on 1.6.8, but I’ll get my 2.x copy up and get back to you shortly. Thank you for the heads up!

       
JmanPro's avatar
JmanPro
49 posts
15 years ago
JmanPro's avatar JmanPro

No prob. Sorry for misunderstanding about the version #. Someone above mentioned 2.x so I thought it meant this was a 2.x plugin. 😊 Thanks again, can’t wait for the proper version!!

       
sm9's avatar
sm9
352 posts
15 years ago
sm9's avatar sm9

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.

       
Jeremy Schultz's avatar
Jeremy Schultz
68 posts
15 years ago
Jeremy Schultz's avatar Jeremy Schultz

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

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.