Daydream Lab
Subscribe to the Daydream Lab [RSS]

“Early Christians transformed the world by thinking different and living different, not by complaining about everybody else’s morals.”

—Alan Wilson

“‘You are destroying yourself,’ he cried. ‘You have the inclination to be alone and to dream and you are afraid of dreams. You want to be like others in town here. You hear them talk and you try to imitate them.’”

—Sherwood Anderson

“On earth we are wayfarers, always on the go. This means that we have to keep on moving forward. Therefore be always unhappy about what you are if you want to reach what you are not.”

—St. Augustine

“In the third month they began to pile up the heaps, and finished them in the seventh month.”

—2 Chronicles 31:7 (ESV)

“There would so much less laughter in the world if evil people stopped talking.”

—MadPriest

“Then I commended mirth, because a man hath no better thing under the sun, than to eat, and to drink, and to be merry…”

—Ecclesiastes 8:15

“Did they teach you how to question when you were at the school? Did the factory help you grow? were you the maker or the tool?”

—Ewan MacColl

“Happiness happens when you are not thinking about it, when you are inhabiting your body comfortably…when you feel at peace with yourself and the world. When we live overprotective, overstimulated lives we expect more all the time, we find it hard to be unself-conscious and just do what we do; we overanalyse.”

—Rowan Williams

“You can never win a war against terror as long as there are conditions in the world that make people desperate—poverty, disease, ignorance, et cetera….I think people are beginning to realize that you can’t have pockets of prosperity in one part of the world and huge deserts of poverty and deprivation and think that you can have a stable and secure world.”

—Desmond Tutu

“The distrust of wit is the beginning of tyranny.”

—Edward Abbey
Contact Me

Elsewhere in my Brain

Archive by category

Archive by date

Custom RSS in Textpattern

Part One: Basics

I’ve been tinkering with RSS in Textpattern for some time now, trying to figure out how to syndicate what Ben calls a hybrid tumblog.

I won’t be covering any new ground with this post—others have written tutorials on this (See this article for an example aimed at would-be podcasters)—but I want to provide my own basic tutorial to build on in the coming weeks and months.

I use one plugin in this tutorial: mg_setheader, which instructs Textpattern to change the HTTP headers to properly identify our feed as XML instead of HTML.

To start with, here’s my standard, Textpattern-generated feed, as of right now:

<?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/?v=4.0.5</generator>
<title>Daydream Lab</title>
<link>http://www.daydreamlab.com/</link>
<description>Thirty Years of Experience in Daydream R&amp;D</description>
<pubDate>Fri, 18 Jan 2008 20:34:25 GMT</pubDate>
<item><title>St. Augustine</title>
<content:encoded>
<![CDATA[<p>&#8220;On earth we are wayfarers, always on the go.  This means that we have to keep on moving forward.  Therefore be always unhappy about what you are if you want to reach what you are not.&#8221;</p>]]>
</content:encoded>
<link>http://www.daydreamlab.com/thoughts/st-augustine</link>
<pubDate>Fri, 18 Jan 2008 20:02:10 GMT</pubDate>
<dc:creator>Adam Bradley</dc:creator>
<guid isPermaLink="false">tag:www.daydreamlab.com,2008-01-18:3ffa0ca248affff16e3d997bfa61988e/e76721d1433883b260acbbad6b229f3a</guid>
</item></channel>
</rss>

I’m going to reconstruct this, from scratch, in a Textpattern Page and two Forms. Here’s the page:

<txp:mg_setheader /><?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/?v=4.0.5</generator>
<title><txp:site_name /></title>
<link><txp:site_url /></link>
<description><txp:site_slogan /></description>
<pubDate><txp:article_custom allowoverride="0" listform="rss_pubdate" limit="1" /></pubDate>
<txp:article_custom limit="10" allowoverride="0" form="rss_basic_article" />
</channel>
</rss>

Which is very simple to create. Copy and paste your feed to the page edit window, then:

  1. Add a <txp:mg_setheader /> tag to the top, to make Textpattern serve this page as XML.
  2. Replace the name of your site, homepage URL, and site slogan with the appropriate Textpattern tags.
  3. Replace the pubDate with the tag <txp:article_custom allowoverride="0" listform="rss_pubdate" limit="1" />. We’ll create the rss_pubdate form next.
  4. Delete everything between the first <item> tag and the last </item> tag—that is, all of your articles—and replace all of that with an <txp:article_custom /> call which will display however-many articles you want in your feed (the call above shows ten) using the form we’re about to create.

Here’s the rss_pubdate form. It simply shows the post date in the appropriate format according to the specification.

<txp:posted format="%a, %d %b %Y %H:%M:%S %z" />

Finally, here’s the article form. The page above assumes it will be called rss_basic_article, but you can simply change that in the article_custom tag.

<item>
<title><txp:title /></title>
<description>
<![CDATA[<txp:excerpt />]]>
</description>
<content:encoded>
<![CDATA[<txp:body />]]>
</content:encoded>
<link><txp:permlink /></link>
<pubDate><txp:posted format="%a, %d %b %Y %H:%M:%S %z" /></pubDate>
<guid isPermaLink="true"><txp:permlink /></guid>
</item>

The Textpattern tags should be mostly self-explanatory—it’s probably a lot simpler than the article forms used on your web pages. Note that pubDate uses exactly the same code we used above for the feed publication date. Also:

  • The form above has both <description> and <content:encoded> sections. Textpattern only puts one of these, depending on whether you choose to syndicate full posts or just excerpts. It’s ok to put both—some feed readers, like Bloglines, will let user choose which to see. It is recommended, according to Feed Validator, that you put content:encoded, with your complete body, after description. Of course, if you don’t want to syndicate entire posts, you can just leave the content:encoded section out.
  • guid is “a string that uniquely identifies the item.” I simply use the article permlink. Textpattern doesn’t use the permlink, but I’m not sure what it does use.

At this point, you should run your feed through a feed validator, to ensure that it works. One problem you may have is the error “XML parsing error: not well-formed (invalid token),” caused by a forbidden character, such as an ampersand, somewhere in your feed (probably your site name or slogan or an article title). These should be escaped (e.g. &amp; instead of &), though you can also wrap the offending outputs in <![CDATA[...]]> tags, so that

<txp:site_slogan />

becomes

<![CDATA[<txp:site_slogan />]]>

I explain in part 2 how to automatically escape these characters.

That’s it for now. I expect to write part two by the end of January; if you’d like to be alerted, you can subscribe to my main RSS feed, or this Textpattern-only feed.

Field Reports:

Commenting is closed for this article.