tips and tricks for movable type

limit excerpt to a paragraph
January 12, 2003

Another example from Brad Choate of what his MTPerlScript plugin can do: extract the first paragraph of your entry to use as an excerpt.

<MTPerlScript>
print '<p>'.(split /\r?\n\r?\n/,<<'ENDOFTEXT')[0].'</p>';
<MTEntryBody convert_breaks="0">
ENDOFTEXT
</MTPerlScript>

Found here.

Comments

hi girlie
i use this code but instead of first paragraph, full text displayed as an excert !
i think this codes showed texts between first <p> and last</p> , that is full text...what should i do to extract the first paragraph as an excert!

by amir mansoori | 09.01.03 05:41 AM

It worked perfectly for me in testing.

Did you install the plugin correctly? Do you have convert breaks turned on in your preferences, or are you coding the <p> tags yourself?

by girlie | 09.01.03 09:11 AM

no... i set convert breaks to NONE in preferences...i put perlscript.pm in :
/cgi-bin/mt/extlib/bradchoate
and perlscript.pl in:
/cgi-bin/mt/plugins/perlscript.pl
and then put that codes in my main index template...
so what is wrong?

by amir mansoori | 09.01.03 03:11 PM

If convert breaks is set to none, then are you coding in <p> tags yourself in your entries?

I assume the script needs some way to know where your first paragraph ends and the next begins in order to know where to split the body.

by girlie | 09.01.03 03:16 PM

what do mean exactly about coding <p> my self? i write a entry in MT editor that has some paragraphs... it means i push Enter key in after some words that i want to be a paragraph...

by amir mansoori | 09.01.03 03:21 PM

for example, right now, i copy and paste your comment as a new entry ( If convert breaks is set to none....) but i shows all of your comment as an excert (If convert breaks is set to none...where to split the body.)!!!

by amir mansoori | 09.01.03 03:25 PM

Do you have a URL where you're trying to get this to work? I'm having a hard time understanding what you're telling me.

by girlie | 09.01.03 03:32 PM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 0
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/131)