
All other factors aside, Wordpress still has one up on Textpattern for custom RSS feeds – a function with quite a lot of potential. Textpattern doesn’t technically offer this capability, but it’s fairly simple to construct an alternative.
Step the First: Page/Section
Open up the Textpattern control panel and scoot over to the Pages area (under Presentation). Create a new page (or copy an existing page); save it as myrss or something clever.
Open up the Sections tab. Create a new section with the same name as your new-and-shiny page. After creating the section, find it in the section list and change the “Uses page” field to myrss. Twiddle with the other settings if you’re terribly bored; we won’t be needing them for anything.
Step the Second: Constructing the Feed
Back to Pages. Open up the myrss page. Delete everything in it, then copy in the following:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<generator>http://textpattern.com/</generator>
<title><txp:sitename /></title>
<link><txp:link_to_home /></link>
<pubDate><txp:php>echo strftime( "%a, %d %b %G %T %Z" );</txp:php></pubDate>
<txp:article_custom allowoverride="0" form="myrss" limit="5" pgonly="0" section="blog" />
</channel>
</rss>
(Note: change the section attribute of txp:article_custom to whatever section you want to be pulling articles from. Also – the presence of the PHP bit means that PHP parsing must be enabled for this to work properly. You can set this in Admin -> Preferences -> Advanced -> Publish -> “Allow PHP in pages?”.)
Save this, then move to the Forms tab.
Step the Third: Custom RSS Items
Open up a blank form (“Create new form”), then paste in the following:
<item>
<title><txp:title /></title>
<description>
<![CDATA[
<txp:body />
]]>
</description>
<link><txp:permlink /></link>
<pubDate><txp:posted format="%a, %d %b %G %T %Z" /></pubDate>
<dc:creator><txp:author /></dc:creator>
<guid><txp:permlink /></guid>
</item>
Name it myrss (or something different; you’ll need to change the page if you go all creative here). Change the form type to “Article” and save it.
Step the Fourth: Slack-Jawed Admiration
You’re done, actually. Or nearly. Load up domain.com/myrss and gaze in wonder.
Now take a step back. You’re here to trick out your feed, and thus far we’ve only created the framework. At this point, you can go back to the myrss article form and have your way with it – anything you put in into the <description> area will be used in the feed at /myrss (check my feed for an example). Article images are a common addition, but anything that Textpattern can do, your feed can use.
(Note: Don’t mess with anything other than <description> unless you know what you’re doing, btw. Feeds break easily.)
Epilogue: The Problem
The only issue with this technique is the content headers. A feed validator will tell you that it’s being served as text/html, and that this is bad. In theory, tacking <txp:php>header( "Content-type: text/xml", true);</txp:php> on to the beginning of the myrss page would fix this, but it doesn’t seem to have an effect. If anyone has any brilliant ideas, leave a note and I’ll add it/them to this article.
Mike has a plugin available that’ll take care of this – download it here. (Thanks, Mike)
In the meantime As an alternative, running the feed through Feedburner will solve your problems (and add even more functionality, actually).
Go in customized-Textpattern-rss peace.
(And yeah, that photo up above is entirely unrelated.)
Fantastic, I have been using a plugin to put the article image in the RSS Feed, but being able to completely customise the feed data will be very very handy for my new site.
Thanks!
great article! I was editing the source code to costimize my rss feed :D
Thanks
Oh! This is just a so smart way to built a customized feed! Perfect! Thanks for the hint!
I’ve hobbled together a plugin that allows you to change the header on a page. The code is Sencer’s. I just threw it into a plugin. Here it is:
http://www.dev.michaelgravel.com/text/plugin-mg_setheader
This is gold sir. Thankyou.
Thanks!
This is simply genius!!!
my rss doesn’t work! I did is written in this article, but it doesn’work: in rss bookmark the article list is always empty. php on page is ok. it could be the muiltilanguage pack plugin?
Do i need to put the MLP’s command
<body dir=”<txp:l10n_get_lang_dir />”
in the myrss page?
thanx
Thanks this is great. I’m new to textpattern and with this (plus help form a couple of Turkish friends) our new website is taking shape quite nicely!
Hi,
Is it possible to mimic the built in RSS features like passing section and category values? As it is now, I need a new page template for each section RSS that I want to modify(?)
cheers,
/Anton
The issue with that is that we’re using a section already, one that’s set up to use the rss page template.
However, if you feel like using another variable in the url string to pass in a section (e.g. foobar.com/myrss/?section=123), replacing the template’s
txp:articletag with the following would do the trick:<txp:php>echo article_custom(array('allowoverride'=>0, 'form'=>'myrss', 'limit'=>5, 'pgonly'=>0, 'section'=>$_GET['section']));</txp:php>Change
myrssto whatever’s appropriate, obviously. It should be fairly clear how the PHP functionarticle_custom()is connected to thetxp:article_customtag; feel free to extrapolate whatever else needs doing from that.HI, I’ve just found this after constructing a geo-feed based on Mike’s mg_setheader – typical!
However, some may find it interesting in that I’ve created a feed just for those articles that contain geo-information and as I do not use excerpts, this feed uses the same Custom fields as my map does, therefore Google maps or other maps that import the feed are presented with a snippet of text that describes the article and an image.
I’ll put the code up in a new article soon, but until then if anyone’s interested you can get the feed from the button at the top of my Map page or click on this link to see the results in Google Maps.
Cheers.