Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2004-07-11 23:36:55
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
[archived] kgr_safe_excerpt
Notice: This thread is archived as this plugin is no longer available.
**********************************************************
I’ve developed a new plugin, found here, which I think may take care of some people’s issues with excerpt handling. It’s designed to operate like Movable Type’s handling of excerpts, in that it will return the excerpt for an article if it exists, otherwise it will only return the first 20 words (but the number of words is configurable).
Recommendations and suggestions for improvement are appreciated.
Update, 1/8/2006: Version 1.0 of the plugin has been released; see the link above to download it. The code has been refactored to be a bit more tidy. In addition, suggestions from previous versions have been incorporated into this version. Be advised, the arguments have changed from the last version, so see the help text:
<blockquote>
Usage: <txp:kgr_safe_excerpt count="100" linktext="Read More" />
The words and linktext parameters are both optional, if omitted, will default to 20 and “more…”, respectively.
If an article has an excerpt, then the plugin will output the excerpt along with a link to the full article. If there is no excerpt,
then the plugin will check the number of words in the article. If the length of the article is under the specified number of words,
then the article will be included verbatim, with no link to the full article. Otherwise, the first count
words will be included,
and all HTML tags will be stripped. This helps to prevent broken HTML (if, for example, there was a <b>
tag in the article, but the closing tag would be cut off by the truncation of the article). Finally, a link to the full article is added.
The plugin takes a total of four optional parameters:
- count: the desired length of the final output, in words or characters
- mode: the unit to use for counting length—defaults to
words
; set tochars
to count characters - countexcerpt: set to
true
to truncate the excerpt as well if it exists but is longer thancount
- linktext: the link text to use; set to an empty string (
""
) to disable the link entirely - styleclass: a CSS class to apply to the the “read more” link
This plugin is based on Douglas Livingstone’s btx_excerpt plugin, but is designed to operate more like Movable Type’s excerpt handling.
</blockquote>
Last edited by KurtRaschke (2006-01-08 22:57:33)
kurt@kurtraschke.com
Offline
Re: [archived] kgr_safe_excerpt
Excellent! Thanks for that plug-in, Kurt, it works just as advertised. Good job of stripping out the HTML to avoid problems with unclosed tags. My only minor quibble is the “more” link that is automatically added at the end of the excerpt. I add a permalink of my own after the text excerpt, which includes an article word count. Since txp:excerpt doesn’t automatically generate anything other than body text, that seems like what should be the “default” behavior. But as I said, that’s a minor quibble. If there’s a way to add an attribute to turn that on or off, that would be great, but I’ll take it either way.
And when you say “the number of words is configurable,” how would you change it from the default of 20?
TextPattern user since 04/04/04
Offline
#3 2004-07-12 00:36:35
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Re: [archived] kgr_safe_excerpt
You can configure the number of words with the “words” parameter to the tag:
<code><txp:kgr_safe_excerpt words=“50” linktext=“Continue reading…” /></code>
I’ll add an option to turn the permalink off entirely in the next version.
-Kurt
kurt@kurtraschke.com
Offline
Re: [archived] kgr_safe_excerpt
Thanks again. I think I’ve found one small and rarely encountered bug, once I used the “words” attribute. If the number of words in an article is less than the amount chosen in the attribute (i.e., a 54 word article when words=“55”), HTML is not stripped from the body.
A few examples can be found on this page
TextPattern user since 04/04/04
Offline
#5 2004-07-12 21:29:27
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Re: [archived] kgr_safe_excerpt
Actually, it’s supposed to work that way. If the number of words is less than the cutoff point, then the entire article is being included in the excerpt. Therefore, there’s no way for a closing tag to get cut off, and so there’s no need to strip the tags.
Note: This behavior is based on the viewpoint that there’s nothing wrong with HTML in excerpts—after all, the excerpt field itself is Textiled, which would tend to generate HTML tags in the excerpt.
kurt@kurtraschke.com
Offline
Re: [archived] kgr_safe_excerpt
OK, I can see the logic of that. It’s only visible to me because of some CSS issues that I can easily fix.
TextPattern user since 04/04/04
Offline
#7 2004-07-15 03:18:53
- msteinruck
- Member
- Registered: 2004-07-14
- Posts: 44
Re: [archived] kgr_safe_excerpt
Okay, I’m clearly doing something wrong. I added this new tag to my article form (since this is how I want my default articles to work). It seems to control the length of the article on the front page, but when you click the Read More link, it only shows the exerpt on the archives page and you never see the entire article. What could I be doing wrong?
Offline
#8 2004-07-15 23:01:41
- KurtRaschke
- Plugin Author
- Registered: 2004-05-16
- Posts: 275
Re: [archived] kgr_safe_excerpt
> msteinruck wrote:
> Okay, I’m clearly doing something wrong. I added this new tag to my article form (since this is how I want my default articles to work). It seems to control the length of the article on the front page, but when you click the Read More link, it only shows the exerpt on the archives page and you never see the entire article. What could I be doing wrong?
You probably want to either use the conditional tags or the listform parameter to the article tag.
Last edited by KurtRaschke (2004-07-15 23:01:53)
kurt@kurtraschke.com
Offline
Re: [archived] kgr_safe_excerpt
I’m wondering if the issues and features (pros and cons) of this plugin and my plugin can be worked out to create a happy medium.
The plugin that I created works a little differently in that it will only include entire paragraphs from an entry, so the wrapping paragraph tags will still be included. Mine also doesn’t add the “Read More” link, you can do this with a form yourself.
I think some solutions to these situations are:
- Only strip the paragraph tags if it doesn’t find a closing tag in the excerpt (or better, add one for it)
- Have the option for a read more link, but have it fully configurable to be able to turn it off and on. Also only include this if the excerpt is less than the full body. (like how MT does this)
I thought I’d start working to perfect these idea, but it would be nice to hear what people think about how excerpts should automatically be created.
Again, the plugin that I created was posted here
Last edited by philipashlock (2004-07-16 00:20:17)
Offline
#10 2004-07-19 19:09:42
- msteinruck
- Member
- Registered: 2004-07-14
- Posts: 44
Re: [archived] kgr_safe_excerpt
Kurt,
Your plugin does exactly what I want it to do. I guess my question, and where I might be going wrong, is where do I place the <txp:kgr_safe_excerpt words=“50” linktext=“Read More”> tag. Do I just replace <txp:article /> on my template? Do I make a new form with it? What’s the best solution?
Offline
Re: [archived] kgr_safe_excerpt
Depending on how you want excerpts to be used, you’d probably put it in place of the txp:body tag in the form used for the default page.
Offline
Re: [archived] kgr_safe_excerpt
I have some problems with your plugin.
I add the tag
<code><txp:kgr_safe_excerpt words=“50” linktext=” read more…” /></code>
to my default form which normaly show the entire article, but now it is showing the entire article following by the ecerpt and the read more link.
My form looks like this:
<code>
<h1><txp:title /></h1>
<txp:body />
<txp:kgr_safe_excerpt words=“50” linktext=” read more…” />
<p style=“clear: left”><strong>Aufgeschrieben von <txp:author /> am <txp:posted /> Uhr<br />
Thema: <txp:category1 /> | <txp:permlink>verlinken</txp:permlink> | <txp:comments_invite /></strong></p>
<p align=“right”><txp:link_to_prev><< <txp:prev_title /></txp:link_to_prev> <txp:link_to_next><txp:next_title /> >></txp:link_to_next></p>
</code>
But what I whnat to do is, when I write an article without an excerpt show the whole article, do I write with an excerpt, show only the excerpt and the link to the entire article.
Maybe my problem is to handle your plugin the right way.
It would be nice if someone can show me what to do.
Visit my Textpattern sites:
Northerndelight | Hasenbude
Curiculum Vitare | Rezepteblock
Offline