
Readers may wish to refer to part one of my summary posts in serendipity blog feeds guide.
After reading a blog post about the need to specify meaningful summaries of posts for rss and atom feeds I decided to take another look at post summarising in serendipity feeds.
In my previous implementation posts were summarised by crude truncation. However I feel that there are more features that can be added for the benefit of the blogger as well as the loyal blog reader. In this post I will write about how to implement the following features:
- Custom post summaries on a per-post basis: Inserting truncated blog posts does have its benefits. It is easy and quick for the blogger but sometimes you want to be able to specify custom teaser text on a per post basis for your rss feeds to attract the reader to your site.
-
Insert a continue reading link: A simple continue reading link that follows the post summary as the next logical step for your readers to take. The link should contain the same anchor text as the post title. This way if your blog feeds are being syndicated on another site you get a seo friendly back link with the keywords you want.
Implementation
To implement this you will have to install the extended properties for entries event plugin.You can do this in configure plugins->click here to install an event plugin. Once you have installed that plugin you will be given the opportunity to create a custom field. Make one field called "postsummary". If you try to edit an entry or create a new one you will find that the new field appears at the bottom of the admin panel page. You can insert your post teaser text in this field.
Custom teaser text is an option. You want it take precedence over truncated posts when available but when it isn't specified for a post s9y should truncate the post automatically.
For the various rss feed versions you would use the following code in between <description> and </description> (<content:encoded> and </content:encoded> for rss 2.0):
{if $entry.properties.ep_postsummary}
{$entry.properties.ep_postsummary|@escape}
{else}
{$entry.feed_body|@strip_tags|@truncate:250:false}...
{/if}
{"<br /><br />"|@escape}
{"Continue reading
< href=\"`$entry.feed_entryLink`\">`$entry.feed_title`</a>"|@escape}
In the above code s9y first checks to see whether a custom summary is specified. If it is then it is used. Otherwise it inserts a truncated post. At the end it inserts a continue reading link.
For atom feeds the logic is similar except that the HTML tags are not escaped:
<div xmlns="http://www.w3.org/1999/xhtml">
{if $entry.properties.ep_postsummary}
{$entry.properties.ep_postsummary}
{else}
{$entry.feed_body|@strip_tags|@truncate:250:false}...
{/if}
<br /><br />Continue reading
<a href="{$entry.feed_entryLink}">{$entry.feed_title}</a>
</div>
The above code is inserted between the opening and closing content tags.
Using the technique outlined above you can protect your content from being scraped while also providing your readers with interesting summaries of your posts in your blog feeds. If you like you can download the full set of s9y summary blog feeds.