Getting My Wordpress Blog Into ColdFusion Using RSS
I wanted to integrate this blog with my existing ColdFusion pages and didn't want to resort to having a seperate php page for my blog. Since Wordpress serves a standard RSS feed, it was simple enough to grab it via RSS. Here's the code:
CFM:
-
<pre><cfcomponent>
-
<cffunction name="getBlog" access="public" returntype="string" output="true">
-
<cfset var blogXML = "" />
-
<cfset var bFormatted = "" />
-
<cfset var tmpDate = "" />
-
<cfset var bArr = "" />
-
<cfhttp url="http://samedwar.setupmyblog.com/?feed=rss2" method="get" />
-
<cfscript>
-
blogXML = xmlParse(cfhttp.fileContent);
-
bArr = xmlSearch(blogXML, "/rss/channel/item");
-
</cfscript>
-
<cfloop from="1" to="#arraylen(bArr)#" index="i">
-
<cfsavecontent variable="tmpBlog">
-
<cfoutput>
-
<div class="blogEntry">
-
<h4 class="blogEntryTitle">#bArr[i].title.xmlText#</h4>
-
<cfset tmpDate = createodbcdatetime(bArr[i].pubDate.xmlText) />
-
<p class="blogEntryDate">#dateformat(tmpDate, "m/d/yyyy")# #timeformat(tmpDate, "h:mm")#</p>
-
-
-
#bArr[i]["content:encoded"].xmlText#</div>
-
</cfoutput>
-
</cfsavecontent>
-
<cfset bFormatted = bFormatted & tmpBlog />
-
</cfloop>
-
<cfreturn bFormatted>
-
</cffunction>
-
</cfcomponent></pre>
-
<div class="blogEntry"></div>
I still have to wire up the links you see to the left, but not bad for an hour's effort.