How to summarise posts in serendipity rss feeds (part 2)

/uploads/feed-icon-64x64.png

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.

8 thoughts on “How to summarise posts in serendipity rss feeds (part 2)

  1. Can’t seem to get this to work, everytime I post the .rss page to the server I am getting an error “Invalid at the top level of the document. Error processing resource”, can you tell what I might be doing wrong. Currently I am going to http://www.golfetail.com/cblog/feeds/index.rss1 taking that content, making the changes above and then saving as a .rss file and posting it on the server. That is when the error occurs. Can you help?

    • You’re not supposed to modify the s9y generated .rss file but the .tpl feed files in your cblog/templates/default folder. Please refer to part one of my post:

      //abdussamad.com/archives/88-How-to-summarise-posts-in-serendipity-rss-feeds.html

      Alternatively you can just download the whole set of .tpl feed files linked in the last paragraph of this post and place them in your default templates folder.

      • Thanks for your response, that cleared things up for me. I have it working using your code. Is it possible to truncate the content to less the 250 characters? I changed 250 to 100 in the code, but that did not work, do I need to do something else?

        • It should work if you made the change in all the files. You should replace this:

          {$entry.feed_body|@strip_tags|@truncate:250:false}

          with this:

          {$entry.feed_body|@strip_tags|@truncate:100:false}

    • The postsummary field has to be *completely * empty. That means not even a single space or new line character. So check it again.

      • Thank you so much…I did have a space in the post summary and would have never figured that out. Another quick question, what is the best way to manipulate the blog font to match the font on your page?

        • You will have to edit the styles.css file in your chosen theme’s folder. You could try setting the body font:

          body
          {
          font-family:verdana,sans serif !important;
          }

          IF that does not work you’ll have to set the font for each of the page elements individually. For ex: the blog post body:

          .serendipity_entry_body
          {
          font-family:verdana,sans serif !important;
          }

Leave a Reply

Your email address will not be published. Required fields are marked *