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>
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!
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?
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?
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.
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...
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.)!!!
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.