x
 
Create New Page
 View Previous Changes    ( Last updated by Lisa Wess )

RSS for multiple weblogs

Question:

How can I set up an RSS/Atom feed that combines entries from more than one weblog?

Answer:

Overview

RSS/Atom feeds are provided by templates, so the first step is to set up a template for the feed, using a normal one-weblog RSS template as a starting point. Be sure to set the template type as “RSS Page”.

There are two main parts of an RSS/Atom template: the first provides basic information about the feed, and the second provides the actual content.

Modifying the channel feed definition

The basic information about the feed is contained in a “channel” element in RSS, or in a “feed” element in Atom. When the RSS feed is for a single weblog, this is straightforward: it’s the information about the weblog that the feed is for. But when you have multiple weblogs, you might need to think for a moment about what you want to have in there.

There are usually five pieces of information in the channel/feed element that you need to consider:

; title : what you call the feed. With a single weblog, it’s the {weblog_name}
; link : the URL of the weblog’s home page. With a single weblog, it’s the {weblog_url}
; description or tagline : what you want the feed’s tag-line to be. With a single weblog, it’s the {weblog_description}
; dc:language or xml:lang : the language that the feed is in. With a single weblog, it’s the {weblog_language}
; dc:date or pubDate or modified : the most recent change to the feed contents. With a single weblog, it’s the {gmt_edit_date} or maybe {gmt_entry_date}

The {exp:rss:feed} tag takes one and only one weblog name, so you’ll have to pick one. The weblog that you choose will determine the values for {weblog_name}, {weblog_url}, {weblog_description}, {weblog_language}, etc. In some cases, that makes the choice obvious. In other cases, there is no obvious choice and the tags like {weblog_name} will have to be replaced with something specific to the feed.

The change date (dc:date, pubDate, or modified) deserves some special attention. You very probably want this to reflect the most recent update to any weblog that is contained in this feed. To do that, you’ll need to wrap the {gmt_edit_date} or {gmt_entry_date} tag with {exp:weblog:entries weblog=“weblog1|weblog2|weblog3” limit=1} and {/exp:weblog:entries} tags. Fill in the list of all of the weblogs for this feed, of course.

Note: that date change is a bit squirrely. The {exp:weblog:entries} tag-pair is enclosed inside the {exp:rss:feed} tag-pair, and both tag-pairs provide {gmt_edit_date} and {gmt_entry_date} variables. The current version of EE (1.2.1) seems to use the variables from the {exp:weblog:entries} tag-pair, which is what we want. But there doesn’t seem to be any guarantee that this will always work in the future.

Modifying the item entry definition

The actual item content is contained in “item” elements in RSS, or in “entry” elements in Atom. To get the feed to contain items from multiple weblogs, simply change the weblog= parameter in the {exp:weblog:entries} tag to something like weblog=“weblog1|weblog2|weblog3” with the list of all of the weblogs for this feed.

If you need to link to different pages for each weblog it can be difficult. One way would probably be to use conditional variables, but the easiest method I found was to use the following:

{exp:xml_encode}{comment_url_title_auto_path}{/exp:xml_encode} 

This will link to the comment page listed in the weblog preferences for each weblog.

While you’re messing with the parameters on the {exp:weblog:entries} tag, you might want to increase the limit= parameter.

Category:RSS

Category:EE1

Categories: