ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Better RSS templates

March 31, 2010 8:19pm

Subscribe [5]
  • #1 / Mar 31, 2010 8:19pm

    While trying to create a more reliable RSS feed, I bumped into several solutions. I’ve put it all together and developed this one:

    {assign_variable:master_weblog_name="blog|technology|science"}
    {exp:rss:feed weblog="{master_weblog_name}"}
    
    <?xml version="1.0" encoding="{encoding}"?>
    <rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:admin="http://webns.net/mvcb/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:content="http://purl.org/rss/1.0/modules/content/">
    
    <channel>
        
    <title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
    <link>{weblog_url}</link>
    <description>{weblog_description}</description>
    <dc:language>{weblog_language}</dc:language>
    <dc:creator>{email}</dc:creator>
    <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
    <dc:date>{gmt_date format="%Y-%m-%dT%H:%i:%Q"}</dc:date>
    <admin:generatorAgent rdf:resource="http://expressionengine.com/" >
        
    {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks"}
    <item>
    <title>{exp:xml_encode}{title}{/exp:xml_encode}</title>
    <link>{title_permalink=blog/post}</link>
    <guid>{title_permalink=blog/post}</guid>
    <description>
    <![CDATA[
    {summary}{body}
    <hr >
    Categories: {categories}<a href="http://{site_url}/blog/category/{category_url_title}/">{category_name}</a>{/categories}
    Tags: {exp:tag:tags entry_id="{entry_id}" type="weblog" orderby="alpha" sort="asc" backspace="2"}<a href="http://{site_url}/tags/tag/{websafe_tag}/">{tag}</a>, {/exp:tag:tags}
    <a href="http://api.tweetmeme.com/share?url={site_url}blog/post/{url_title}">http://api.tweetmeme.com/imagebutton.gif?url={site_url}blog/post/{url_title}</a>
    ]]>
    </description>
    <dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i%Q"}</dc:date>
    </item>
    {/exp:weblog:entries}
        
    </channel>
    </rss>
    
    {/exp:rss:feed}

    Please compare this file with the default one at: http://expressionengine.com/templates/source/category/feeds/

    Details:

    1. The “|” in line 1 indicates more than one weblogs, in this example: blog, technology and science

    2. In the first <dc:date> tag I removed the default %s because it makes an updated post reappear as a new one in feed readers. I also removed the #When:{gmt_entry_date format="%H:%i:%sZ"} in the <guid> tag for the same reason.

    3. The CDATA declaration helps the feed understand the HTML tags in the relevant template. Without it in your feed reader you get text unformatted at all.

    4. Inside the CDATA I added some real HTML code. In particular there’s a horizontal line and the the category and the tags of the post.  Both are clickable and send you in the relevant category/tag in your website. In order to get the tags you ‘ve got to install the Solspace tag module.

    5. The last tag includes the code you need in order to see in your reader the Tweetmeme button, which of course is clickable.

    6. Since we have our clickable categories and tags we don’t need the following line

    <dc:subject>{exp:xml_encode}{categories backspace="1"}{category_name}, {/categories}{/exp:xml_encode}</dc:subject>

    which is a part of the default template.

    Please feel free to test this template and make it better.

    Two excellent sources:
    - http://23rdworld.com/2009/12/23/how-to-fix-your-expressionengine-rss-template/ (this one explains how to make your published post not reappear as new in your feed reader after being edited.)

    - http://www.ablognotlimited.com/articles/customizing-expressionengine-rss-template/ (this one explain how to include clickable categories and tags in your feed)

  • #2 / Apr 01, 2010 1:05am

    John Henry Donovan's avatar

    John Henry Donovan

    12339 posts

    yiannis,

    Thanks for sharing. If you have time you might consider adding this to our Wiki

    I am going to move this thread to the How to forum for you as it is more appropriate there.

  • #3 / Apr 01, 2010 5:58am

    I just added it to the Wiki. Thanks for letting me know.

  • #4 / Apr 28, 2010 9:52pm

    mhulse

    329 posts

    Thanks for posting! Definitely nice to see a clean template.

    I have been using this approach (discussion here) for quite a while now.

    Anyway, I really dig the tweetmeme button! Also, I am glad to see that we can ditch the #when… I really hated that part. Personally, I would avoid putting my e-mail link in the feed.

    Not sure if this is an improvement, but it might be cool to make it an MRSS feed. (Yahoo’s feed is a good example.)

    For example, I quickly added:

    xmlns:media="http://search.yahoo.com/mrss/"

    to the <rss> tag, and then included:

    <media:content ... >
    <media:text ... >
    <media:credit ... >

    ... inside of the <item>.

    Next, I put an article image inside of the <description>, within the CDATA tags, which made my feed reader happy. 😊

    Oh! I also setup a conditional that shows the “full” body (vs. an excerpt) if segment_X == “full”. Kinda nice if you need to display all of your entry’s content.

    It would be cool to hear what other folks are doing?

    Thanks for posting!
    Micky

  • #5 / Apr 30, 2010 6:11pm

    mhulse

    329 posts

    I just found this example:

    URL: http://23rdworld.com/2009/12/23/how-to-fix-your-expressionengine-rss-template/

    Template includes optional changes from the default EE RSS template that I added as a result of various articles, the RSS 2.0 spec and by examining the feeds of major professional news sites. For more information see my blog post (url above). Tested and validated at http://feedvalidator.org. (The default EE RSS feed does not.)

    {assign_variable:master_weblog_name="BLOG"}
    {assign_variable:master_weblog_status="OPEN"}
    {assign_variable:master_rss_uri="http://PATH/TO/THIS/RSS/FEED"}
    
    {exp:rss:feed weblog="{master_weblog_name}" status="{master_weblog_status}"}
    <?xml version="1.0" encoding="{encoding}"?>
    <rss version="2.0"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom">
        <channel>
        <title>{exp:xml_encode}{weblog_name}{/exp:xml_encode}</title>
        <link>{weblog_url}</link>
        <description>{weblog_description}</description>
        <dc:language>{weblog_language}</dc:language>
        <dc:creator>{email}</dc:creator>
        <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
        {gmt_date format="%D, %d %M %Y %H:%i:%s %T"}</pubDate>
        <atom:link href="{master_rss_uri}" rel="self" type="application/rss+xml" >   
    {exp:weblog:entries weblog="{master_weblog_name}" limit="10" rdf="off" dynamic_start="on" disable="member_data|trackbacks" status="{master_weblog_status}"}
        <item>
          <title>{exp:xml_encode protect_entities="yes"}{title}{/exp:xml_encode}</title>
          <link>{title_permalink=site/index}</link>
          <guid isPermaLink="false">{title_permalink="site/index"}#id:{entry_id}#date:{gmt_entry_date format="%H:%i"}</guid>
          <description><![CDATA[{summary}{body}]]></description>
          {categories}<category>{exp:xml_encode protect_entities="yes"}{category_name}{/exp:xml_encode}</category>
          {/categories}
          {gmt_entry_date format="%D, %d %M %Y %H:%i %T"}</pubDate>
        </item>
    {/exp:weblog:entries}
        </channel>
    </rss>
    {/exp:rss:feed}

    Anyway, just thought it would be good to share another example.

    I noticed that my dc:dates were not getting through the feed validator, so I swapped them to <pbuDate> (like in code sample above).

    Other differences: <atom:link ... > and the removal of generator agent.

    If you are using PHP, here is one way to dynamically set the atom:link href:

    <atom:link href="<?='http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']?>" rel="self" type="application/rss+xml" >

    Cheers!

    Micky

  • #6 / May 12, 2010 4:45pm

    Marc Miller's avatar

    Marc Miller

    84 posts

    @yiannis: Your date format wouldn’t validate for me. I had to use:

    <dc:date>{gmt_entry_date format="%Y-%m-%dT%H:%i:%s%Q"}</dc:date>

    Very minor difference - Feedvalidator.org needed the %s to be there.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases