Wednesday November 2, 2005

Textpattern: Clean RSS Feeds & Feed Updates

Author’s note: Tested only on Textpattern 4.0 – 4.0.2.

Feed Me!

I was reminded in my last article that I had implemented clean RSS feeds on this site and never announced it or explained how it was accomplished. Truth be told, I thought that Jeremy Koempel would publish the code, since he basically handed it to me on a silver platter. Others may have done this before, and it may be published in other places, but the following is an explaination of how to achieve what I’d like to call Koempelized Clean Feeds™.

When I upgraded to TXP 4.0 from the release candidate, there were a lot of changes. Textpattern no longer operated sections off of cruft files, so previous clean feed solutions were broken. Being a PHP wuss, I whined about it a fair amount. Though he didn’t comment on it in that article, Jeremy emailed me a solution that was dead simple.

I should first point out that the main RSS feed for Textpattern sites—the one that aggregates articles from every section you choose to syndicate—did not require any trickery on my part. It worked right off the bat at http://www.jaredigital.com/rss.

The basic angle to Koempelized Clean Feeds is much like the old feed solution: move the feed code outside of the Textpattern installation. Here’s the breakdown:

Step 1: Create a new folder on your desktop. Name it whatever you want your feed to be named, e.g. rss-links.

Step 2: Create a new PHP file inside your new folder called index.php and paste in the following code:

<?php
- placeholder -
?>

Step 3: Determine Textpattern’s path to your feed. Textpattern constructs paths to its feeds differently for sections and links. A full path to a section in our PHP file would be constructed as:

header('location: /?rss=1&section=section_name');

where section_name would be replaced with the name of the section you want the feed to link to.

A full path to a link list in our PHP file would be constructed as:

header('location: /?rss=1&area=link&category=your_category');

where your_category would be replaced with the name of the link category you want the feed to link to.

Replace the - placeholder - line in your index.php code with either a path to your article section or links category as outlined above. So the full code for my links feed, for example, is:

<?php
header('location: /?rss=1&area=link&category=general');
?>

Step 4: Upload your new folder to your site root. You can now access your clean feed by using the URL of your new folder!

http://www.yoursite.com/your-folder-name

This is a basic redirection tactic and there are surely other ways to accomplish it (.htaccess, anyone?). It may have also been done exactly in this way by someone else, but it worked so well for me that I figured others could benefit from it as well.

Once again, thanks go to Jeremy for introducing me to this solution.

Since we’re talking about feeds…

With my integration of the Loving… entries into a proper Textpattern section, those articles are being automatically rolled into the default RSS feed. If you think my taste in music and movies isn’t worth jack, or you’d rather not read my gushings about my latest favorite CD right alongside my regular articles, you can now pick and choose your feeds. Enjoy.

Commentary


Mat » 4369 days ago #

Thank you sir. I shall attempt the discussed steps later today and advise on my success – or lack of.

Nathan Smith » 4369 days ago #

Jared: This is a bit off-topic, but have you noticed how TXP comments are now wrapped in P tags by default? This is really weird that they’d do this, because it essentially breaks validation, putting P within P for your site, and on mine, messing with the margin-left / right on P tags within LI.

It’s like we’ve taken 2 steps forward (404 handling = good), but one step back.

Jared Christensen » 4369 days ago #

Mat - Good luck to you! Let me know how it works out.

Nathan Ė Yeah, I hadnít noticed that. Itís actually good news. Before, you had to specify the < p> tags in the form, but now itís built into the tag. Iíll let you know if it brings on any unexpected headaches.

Mat » 4369 days ago #

After a couple of bumps, I have now successfully jumped into the world of clean feeds. Thanks again Jared.

Nathan Smith » 4368 days ago #

Jared: I agree, it’s semantically more correct, but it will force a whole lotta people to have to go back and accomodate these new P tags. I just added a style that got rid of side margins for P within LI, and that nipped it in the bud. I’m not sure about the correctness of paragraphs within list items, but it validates as XHTML 1.1, so I’m not sweating it too much.

Jared Christensen » 4368 days ago #

It was pretty easy for me as well. I just deleted the paragraph tags wrapping my comment output tag and I was done.

Nathan » 4368 days ago #

Know what’s weird though? The left Textile parsing everything, including Headers. Example…

Nathan’s H3

Nathan » 4368 days ago #

Feel free to delete that above comment, since it looks so out of place. Just wanted to give an example.

Jared Christensen » 4368 days ago #

Nah, you make a good point. Getting code to display correctly in articles and comments is the biggest headache EVER. If youíre using Textile, why are HTML tags still enabled? Itís wierd.

EDIT - My brain was on vacation when I replied to Nathan's comment. His point was that he could use Textile to insert an H3 in my comments, which was previously restricted because Textile only parsed certain tags in comments. Now it parses all of them!

Nathan Smith » 4368 days ago #

Yeah, I’m kinda irked by it, but nobody else on the TXP forum really seems to care. I guess I might get around it by linking to the parts of the Textile help that I’d like people to use, and sort of leave out the parts that break things. :)

Brian » 4364 days ago #

Nathan: Although it adds extra, maybe unecessary styles, you can make styles for comments that are just basic styling (no images, etc…). Or, another option is to only allow some tags in comments. I don’t know if that exists within TXP yet, but it would be a good idea.

Jared Christensen » 4364 days ago #

To read about a fix to the problem of too many Textile tags being allowed in comments, check out Nathan’s writeup.

Jeff Adams » 4355 days ago #

New textpattern plugins you might find useful: Clean Feeds and Comment Feeds

Jared Christensen » 4355 days ago #

Sweet mamma pajamas! Those plugins look great! Thanks for the heads up, Jeff.

« Older writing is available in the Archives.