Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2011-11-09 16:59:17
- vickilh
- Member
- Registered: 2007-10-30
- Posts: 96
How to set up RSS feed?
I’ve searched for the past two hours, trying to figure out exactly how to set up an RSS feed for a particular section/category. Perhaps I’m being dense, but I’m not finding anything that lays it out. (there was a blog item by Isaac xxx, but that’s gone.)
I see that there is a “feed_link” tag. But how exactly is this used? Where do I put it? I generated the tag and tried adding it to a Page template, but nothing shows up.
Help!! Thanks, Vicki
Offline
Re: How to set up RSS feed?
Hi Vicki
place something like this in the <head>
<txp:feed_link flavor="atom" format="link" label="Atom" section="some_section" category="some_category"/>
<txp:feed_link flavor="rss" format="link" label="RSS" section="some_section" category="some_category" />
and optionally something like this in the body
<txp:feed_link flavor="rss" section="some_section" category="some_category" label="XML" wraptag="p" />
<txp:feed_link flavor="atom" section="some_section" category="some_category" label="XML" wraptag="p" />
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2011-11-09 18:39:51
- vickilh
- Member
- Registered: 2007-10-30
- Posts: 96
Re: How to set up RSS feed?
Hello, — That’s what I’ve got, but nothing shows up in the body. And nothing shows up in the source code.
Offline
#4 2011-11-09 18:56:33
- vickilh
- Member
- Registered: 2007-10-30
- Posts: 96
Re: How to set up RSS feed?
More detail:
In my test page template, I have this in the <head>:
<txp:feed_link category="01. Recent News" flavor="rss" format="link" label="<img src='mysite.org/images/rss.gif'>" section="News" />
And in the body, just below where the article tag is, I’ve got:
<txp:feed_link category="01. Recent News" flavor="rss" format="link" label="<img src='mysite.org/images/rss.gif'>" limit="20" section="News" title="Recent News" wraptag="p" />
But nothing shows up on a web page that uses this page template/section, and nothing is in the source code. Any ideas?
Offline
#5 2011-11-09 19:36:55
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: How to set up RSS feed?
From the feed_link wiki page:
Note: the category name may be different to the Title you typed when you created the category, as the names are sanitized for URL use. Check the Categories tab to ensure you are using the correct name.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#6 2011-11-10 15:02:47
- vickilh
- Member
- Registered: 2007-10-30
- Posts: 96
Re: How to set up RSS feed?
Ah! The section name was wrong, I’d forgotten changing it slightly a while back. (Sorry!) But in the meantime, I’d created a feed manually. Which is cleaner and seems to work better anyway.
Here’s the code, it should work with other txp situations. Note that the feed fields are very picky about punctuation and various other things, – Be sure to run your feed through the validator. —
<?php
header('Content-Type: text/xml');
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>News from Org-name</title>
<description>What is new</description>
<link>http://mysite.org</link>';
include('your-DB-connectFile.php');
$recentNewsCat = 'Recent-News';
$dc = new DataConnect();
$dc->connect();
$sql ="SELECT * from textpattern WHERE (Category1 ='$recentNewsCat' OR Category2 = '$recentNewsCat')" ." AND Status = 4 ORDER BY LastMod DESC LIMIT 15";
$news_rs = $dc->execute($sql);
while($row = mysql_fetch_array($news_rs)) {
echo '
<item>
<title><![CDATA[ '.$row[Title].' ]]></title>
<description><![CDATA[ '.$row[Excerpt].' ]]></description>
<link><![CDATA[ http://mysite.org/txp/?s=News&id='.$row[ID].' ]]></link>
<pubDate>'.date(DATE_RSS, strtotime($row['LastMod'])).'</pubDate>
</item>';
}
echo '</channel>
</rss>';
?>
Offline
Re: How to set up RSS feed?
You could do exact same with article_custom without all that PHP, and the feeds do produce pretty much same too.
Anyways, there are some things with your code:
- Textpattern uses UTF-8, not ISO-8859-1. A feed reader that follows your encoding declaration, or has different default, won’t show content correctly.
- It produces some notices due to syntax errors. Neither Excerpt or ID is a constant.
- Excerpt contains raw content, while Excerpt_html is the actual formatted content. Unless you format your articles with raw HTML, the content may look pretty plain and contain non-escaped characters. Also relative URLs can cause problems — hope you don’t have any.
- Including GUID for the items would be a good idea. Unless you know that the URL newer changes and can be sure that no reader requires GUID.
Offline
Pages: 1