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: Eexcerpt - Strip HTML and limit words

Development and Programming

Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Oops, thought I had added the md_ prefix to the instructions. It’s on my to-do list - thanks for pointing it out. Glad it’s working for you now!

       
Cecily's avatar
Cecily
24 posts
16 years ago
Cecily's avatar Cecily

Hi,

I’m new to EE and new to this plugin, so I hope you’ll be patient with my newbie question….

… but where exactly do I put the tags for the plug in? I currently have the front page of my blog set up this way:

{exp:weblog:entries weblog="default_site" disable="" limit="4"}
            
            
            <h2><a href="http://{title_permalink=" class="">{title}</a></h2>
            {date_heading}
            {entry_date format="%d %M %Y"}
            {/date_heading}
            {body}
             <a href="http://{title_permalink=" class="">[click to continue...]</a>
            {0 comments}
            <hr >
            {/exp:weblog:entries}

Should I wrap all of that in the Eexcerpt tag? Should I be replacing something? Thanks for the help.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Cecily: You only need to wrap the plugin tags around what you’re trying to shorten. I’m assuming, in this example you want to make an eexcerpt of the body. So I would do this:

{exp:weblog:entries weblog="default_site" disable="" limit="4"}
 <h2><a href='{title_permalink=group/template}' class="">{title}</a></h2>
  {date_heading}
   {entry_date format="%d %M %Y"}
  {/date_heading}

{exp:md_eexcerpt if_exceeds="250" stop_after="100" 
the_link="<p class='meta'><a href='{title_permalink=group/template}' class=''>[click to continue...]</a></p>"}
{body}
{/exp:md_eexcerpt}

{0 comments}
<hr >
{/exp:weblog:entries}

That should take the contents of all four {body} tags (you set a limit of 4) and chop them to 100 characters and tack the link onto the end, but only if the body exceeds 250 characters.

       
Cecily's avatar
Cecily
24 posts
16 years ago
Cecily's avatar Cecily

Thanks for the reply, Ryan.

When I use the code above, I get this error:

Error

The following tag has a syntax error:

{exp:eexcerpt}

So I used the suggestion up thread about changing the tag to

{exp:md_eexcerpt}

and that seemed to do the trick. Thanks so much for the help and the plugin!

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Yep, that’s right - I recently renamed the plugin “md_eexcerpt” so use that instead. Glad it’s working for you. I’ll edit the code above in case someone else comes along and copies/pastes.

       
Sean C. Smith's avatar
Sean C. Smith
3,818 posts
16 years ago
Sean C. Smith's avatar Sean C. Smith

Ryan,

when visiting the plugin manager page the code example has the correct opening tag, but the closing tag is wrong. its missign the md_ prefix.

{exp:md_eexcerpt if_exceeds="60" stop_after="40" append=" →" the_link="<a href='{title_permalink=weblog/comments}’>MORE…</a>”}text you want processed{/exp:eexcerpt}
       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

Oops. Nice catch. I fixed that and pushed the tweaked version to the MD Eexcerpt repo at GitHub.

       
BackBeat Media's avatar
BackBeat Media
76 posts
15 years ago
BackBeat Media's avatar BackBeat Media

I was wondering if

if (($theCount <= $stop_after) && ($theCount < $if_Exceeds))

should be

if (($theCount <= $stop_after) || ($theCount < $if_Exceeds))

Perhaps I don’t understand how to use this plugin, but I take

if_exceeds - Text will be truncated if it is greater than this number of words. This parameter must be included.

To mean this plugin will only trim theCount > if_exceeds.

So given the text “The quick brown fox jumped over the lazy red dog” (theCount = 10)

if_exceeds=11 stop_after=9 should not trim, correct?

But if ((10 <= 9) && (10 < 11)) returns false, allowing the script to continue onto trimming… yes? Or am I not following something?

       
benek's avatar
benek
189 posts
15 years ago
benek's avatar benek

I’m getting an error:

Notice: Undefined offset: 20 in XXXXXX…/plugins/pi.md_eexcerpt.php on line 101

On one of my pages using this plugin, but not on other pages that use it in the exact same way. So it seems like other content or tags on that one page are causing the problem but I can’t find anything.

Any ideas on what might cause that error?

edit went back and read all comments. Looks like it’s still the same old issue where the text is shorter than the exceed limit. I though this was fixed in the newest version but apparently not. Can you please let me know how to fix this issue?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

@benek: I’m finding this happens when the content you want to excerpt is exactly the number of characters is the same as one of the parameters. I haven’t tested this in a while, though.

@Stephen (tmoswift): You probably have stronger analytical powers than I do. You’re probably right about that. Looks like this add-on might need a couple updates.

       
benek's avatar
benek
189 posts
15 years ago
benek's avatar benek

OK, so if that’s the problem, is there any solution?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

I altered some logic and did a lot of local testing tonight. I used all sorts of combos between if_exceeds and stop_after. I think I have this solved. The new 1.1.1 version of MD Eexcerpt is at GitHub. Give it a shot and let me know if you’re getting any errors.

       
benek's avatar
benek
189 posts
15 years ago
benek's avatar benek

New version works great for me. Fixed the error I was getting when the text exactly matched the exceed limit. Thank you so much for the new version.

       
trixpan's avatar
trixpan
9 posts
15 years ago
trixpan's avatar trixpan

great plugin.

May I ask you for an additional feature? What about replacing newlines for spaces as well? 😊

Cheers

       
Ryan M.'s avatar
Ryan M.
1,511 posts
15 years ago
Ryan M.'s avatar Ryan M.

@trixpan: Is it not replacing newlines with spaces for you? I juts did some tests and I think line 81 is taking care of that.

$str = str_replace("\n", " ", $str);
       
1 2 3 4

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.