Creating an RSS feed for your site
Step 1) Create your RSS feed.
Create a template named "rss.tpl" and copy and paste the template written below. You will have to adjust the template tags to fit your site. For example, you should change the channel information such as the title and link, and the tags inside the "<description>" element ("{{ $campsite->article->intro }} {{ $campsite->article->full_text }}").
The PHP code at the beginning and end of the sample below is so that the HTTP header is set to "text/xml" instead of "text/html".
Step 2) Create the link to your RSS feed.
You can do this by using the "URI" keyword:
{{ local }}
{{ unset_issue }}
{{ unset_section }}
<a href="{{ url options="template rss.tpl" }}">RSS Feed</a>
{{ /local }}
If your template is not in the root directory but in a sub folder (in this case the folder named "feeds") you have to specify the URL options as a relative link, e.g.:
{{ local }}
{{ unset_issue }}
{{ unset_section }}
<a href="{{ url options="template feeds/rss.tpl" }}">RSS Feed</a>
{{ /local }}
The following template contains the necessary commands for a valid RSS feed. However, you can alter the list command any way you like to make more than one RSS feed. The following example lists the latest 20 items listed on the front page.
rss.tpl template:
{{ php }}
ob_start();⁞
{{ /php }}
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel rdf:about="http://www.sourcefabric.org">
<title>Sourcefabric News</title>
<link>http://www.sourcefabric.org</link>
<description>Free Software for a Free Press</description>
<dc:language>en-us</dc:language>
<items>
<rdf:Seq>
{{ local }}
{{ set_language name="English" }}
{{ set_current_issue }}
{{ unset_section }}
{{ list_articles length="20" constraints="OnFrontPage is on" order="bydate desc" }}
<rdf:li rdf:resource="{{ url options="article" }}"/>
{{ /list_articles }}
{{ /local }}
</rdf:Seq>
</items>
</channel>
{{ local }}
{{ set_language name="English" }}
{{ set_current_issue }}
{{ unset_section }}
{{ list_articles length="20" constraints="OnFrontPage is on" order="bydate desc" }}
<item rdf:about="{{ url options="article" }}">
<title>{{ $campsite->article->name }}</title>
<link>{{ url options="article" }}</link>
<description><![CDATA[{{ $campsite->article->intro }} {{ $campsite->article->full_text }}]]></description>
<dc:date>{{ $campsite->article->publish_date|camp_date_format:"%Y-%m-%dT%H:%i:%S+01:00" }}</dc:date>
</item>
{{ /list_articles }}
{{ /local }}
</rdf:RDF>
{{ php }}
header("Content-type: text/xml");
$content = ob_get_clean();
echo '<?xml version="1.0" encoding="utf-8"?>';
echo $content;
{{ /php }}
Tips & tricksIf you use XSL, the CDATA sections do not work with Firefox.
If you dont want to use CDATA sections in your RSS, you can strip the HTML from your article this way:
$allowedTags="<rdf:RDF><rdf:Seq><rdf:li><channel><title><link><description><dc:language><dc:date><item><items>"; $content = strip_tags($content, $allowedTags);
Another way to create a link to your RSS feed
Assign the template to a section: create a new section (doesnt matter where), and call it "rss". Configure the section so that its templates are "rss.tpl", and give the section the URL name of "rss". The URL for this section will be the URL to your RSS feed.





