RSS is rapid­ly becom­ing a pop­u­lar for­mat for pro­vid­ing con­tent. It allows users to sub­scribe to bits of infor­ma­tion, so they can be noti­fied when new infor­ma­tion has been post­ed.

I’ve been toss­ing around the idea of imple­ment­ing RSS at work late­ly, and want­ed to do it with Cold­Fu­sion. I final­ly buck­led down and put some­thing togeth­er. Sur­pris­ing­ly, it was much eas­i­er to do that I thought it would be, and I end­ed up cre­at­ing RSS feeds for news arti­cles, upcom­ing events, and job oppor­tu­ni­ties.

Here’s the process I used to cre­ate the RSS feed for job oppor­tu­ni­ties.

The first thing in my CFM file is a block of code that makes sure no HTML out­side of the cfout­put tag gets dis­played:

<cfsetting enablecfoutputonly="yes">

Then the query:

<cfquery name="qCareers" datasource="xxx">
ORDER BY Position

Then I imple­ment a cfsave­con­tent tag. This makes sure that all the con­tent between these two tags is saved as a vari­able. The clos­ing tag appears lat­er.

<cfsavecontent variable="theXML">

Then comes my out­put. It is impor­tant than the root tag in XML for an RSS feed is “chan­nel”, that the title of the feed is in a “title” tag, feed descrip­tion is in “descrip­tion”, a link to the HTML con­tent of the feed is in a “link” tag. As well, every item should be with­in an “item” tag, which also con­tains “title”, “descrip­tion” and “link” tags. Not fol­low­ing that for­mat will cause your RSS feed to fail.

In addi­tion, there must be an “rss” tag, and there must be no white space (includ­ing a new line) between the open­ing “cfout­put” tag and the “xml” tag.

<cfoutput><?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">

<title>Faculty of Management - Jobs</title>
<description>Current Career Opportunities</description>
<cfloop query="qCareers">
<description>#Details# <cfif NOT IsDefined("StartDate") OR StartDate DOES NOT CONTAIN "1999">Commences #DateFormat(StartDate,'dd mmmm yyyy')#.</cfif></description>

Close the cfsave­con­tent tag, as pre­vi­ous­ly men­tioned.


Then out­put the vari­able that con­tains it all.

<cfcontent type="text/xml">

Sim­ply upload this file to your serv­er some­where, and add the fol­low­ing into the page where you want the RSS feed avail­able.

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="" />

Sim­ple as that.

About Kim Siever

I am a copy­writer and copy­ed­i­tor. I blog on writ­ing and social media tips most­ly, but I some­times throw in my thoughts about run­ning a small busi­ness. Fol­low me on Twit­ter at @hotpepper.

Free monthlywriting &social media tips!

Free monthlywriting &social media tips!

Sign up to receive monthly writing and social media tips.

Thanks for signing up for our monthly writing tips!

Pin It on Pinterest