Jump to Content
Kimili
  • Journal
  • Portfolio
  • Projects
  • About
  • Contact

Molding Textpattern XML Feeds

21 Jan 05

As I was building this site and turned my attention to the RSS and Atom feeds that Textpattern generates, I found them to be pretty flexible. Out of the box, you can generate and send:

  • feeds of all available articles
  • feeds of all available links
  • feeds of articles or links filtered by section
  • feeds of articles or links filtered by category
  • feeds of articles or links filtered by section and category

For article feeds, you have the option to display either full articles or excerpts. In this site’s journal section, I use the excerpt for the article summary on the landing page and the full text for the article itself. Being such, I thought it would be good to offer feeds for both the excerpts and the full articles. Twenty minutes and a small bit of hackery later, I had it down. Here’s how I did it.

Have It Both Ways

Note: The following mods were performed on Textpattern 1.0rc1

There are 2 files that you’ll have to edit in order to get your choice full or summarized feeds. They are:

  • /textpattern/publish/rss.php
  • /textpattern/publish/atom.php

These are the files that generate your XML feeds and as they are quite similar in function and structure, once you make the changes in one file, it’s a peice of cake to apply them to the other.

Since accessing and filtering different feeds depends on the query string used in the feed URL, lets take a look at how that is structured. Accessing the following URL:

http://www.kimili.com/?rss=1&area=article&section=journal&category=web

would give you an RSS feed of any articles (area attribute) available in the “journal” (section attribute) filed under “web” (category attribute). In order to choose whether we want excerpts or full articles, we’ll need to pass another flag which I’ll call type. I could add it to the URL like this:

http://www.kimili.com/?rss=1&area=article&section=journal&category=web&type=full

RSS

In the second URL above, textpattern doesn’t recognize the type flag and will simply ignore it. We have to tell textpattern what to do with it. Open up /textpattern/publish/rss.php and find the following on line 62:

$Body = (!$txpac['syndicate_body_or_excerpt']) ? $Body_html : $Excerpt;

The “syndicate_body_or_excerpt” refers to your default setting for what you want your XML feeds to spit out. You can set this in /textpattern/lib/admin_config.php, “0” for full articles and “1” for excerpts. Mine is set to “1”.

Back in rss.php, change line 62 to read this:

$Body = (!$bFilter) ? $Body_html : $Excerpt;

Then add the following to define the $bFilter variable on line 59, just above if($rs) {:

$bFilter = $txpac['syndicate_body_or_excerpt'];
	

if ($type) { if ($type "full") $bFilter = 0; if ($type “excerpt”) $bFilter = 1;
}

That’s all you need in order to select whether you want an RSS feed of full articles or excerpts. Just add type=full or type=excerpt to your feed url to make the choice. If you omit it, the feed will simply revert to whatever you’ve set in your admin preferences.

Atom

Setting the same functionality up for Atom feeds is very similar to RSS. First, open up /textpattern/publish/atom.php and change line 90 to the following:

$Body = (!bFilter) ? $Body_html : $Excerpt;

Next, add the following between line 65 and 66:

$bFilter = $txpac['syndicate_body_or_excerpt'];
	

if ($type) { if ($type "full") $bFilter = 0; if ($type “excerpt”) $bFilter = 1;
}

Save your file and that’s all there is to it. Your Atom feeds will now work the same way as the RSS when you add the type attribute to the feed URL.

Comments

Erik V. says:
1093 days ago ∞

Thanks for the helpful tips. Do you know if it works the same way in 4.0?

Michael Bester says:
1093 days ago ∞

I haven’t yet upgraded to version 4, and don’t have a definitive answer at this point. I did look through rss.php and atom.php in the version 4 package and although some things have changed, it seems as if this is doable with some modification.

When I do get around to upgrading, I’ll do my best to update this article with any new findings.

Comments closed.


Flickr

  • Le Crueset
  • Business Cards
  • kimili.com
  • kimili.com
  • kimili.com
  • Sunflower

See more at Flickr

Recent Listening

  1. Charlie Parker - Best of The Complete Savoy & Dial Studio Recordings
  2. Charlie Parker - Bird's Best Bop on Verve
  3. Medeski, Martin & Wood - End of the World Party (Just in Case)
  4. John Coltrane - Giant Steps
  5. David Fiuczynski & Rufus Cappadocia - KiF
  6. Thom Yorke - The Eraser
  7. Getz/Gilberto - Stan Getz, Joao Gilberto
  8. Pat Metheny - Bright Size Life
  9. Miles Davis - Bitches Brew

See more at Last.fm

Tweet, Tweet

  • New Vonage phone number prefix just so happens to be the Number of The Beast. ::Mëtäl Hörnz:: Aug 21st
  • Gonna drop cable TV, too. That's just not worth keeping. Aug 21st
  • Going back to Vonage just before Comcast's TriplePlay bundle price balloons out of control. Aug 21st
  • Looks good, @blacksceva, even for an omnivore like myself. Aug 18th
  • Where'd all your hair go, @doctyper? Aug 18th

See more at Twitter

©MMVIII Michael Bester