Rob Gonda's Blog

Google Sitemap for blogCFC 4.0

A few months ago Ray posted some code to generate a google sitemap.xml for blogCFC. He said it’s not final and it will be included in version 4… I guess there was no demand, or no one reminded him because it wasn’t included… In case anyone needs it, here’s a slightly altered version of the code to work for everyone.

<cfsetting enablecfoutputonly=true showdebugoutput=false>
<cfprocessingdirective pageencoding="utf-8">

<cfset params = structNew()>
<!--- Should be good for a while.... --->
<cfset params.maxEntries = 99999>
<cfset params.mode = "short">

<cfset entries = application.blog.getEntries(params)>

<cfset z = getTimeZoneInfo()>
<cfif not find("-", z.utcHourOffset)>
   <cfset utcPrefix = "-">
<cfelse>
   <cfset z.utcHourOffset = right(z.utcHourOffset, len(z.utcHourOffset) -1 )>
   <cfset utcPrefix = "+">
</cfif>

<cfset dateStr = dateFormat(entries.posted[1],"yyyy-mm-dd")>
<cfset dateStr = dateStr & "T" & timeFormat(entries.posted[1],"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & ":00">

<cfcontent type="text/xml"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
   <url>
      <loc>#GetDirectoryFromPath(application.blog.getProperty("blogURL"))#</loc>
   <lastmod>#dateStr#</lastmod>
      <changefreq>hourly</changefreq>
      <priority>0.8</priority>
   </url>
   </cfoutput>
   <cfoutput query="entries">
      <cfset dateStr = dateFormat(posted,"yyyy-mm-dd")>
      <cfset dateStr = dateStr & "T" & timeFormat(posted,"HH:mm:ss") & utcPrefix & numberFormat(z.utcHourOffset,"00") & ":00">
      <url>
      <loc>#xmlFormat(application.blog.makeLink(id))#</loc>
      <lastmod>#dateStr#</lastmod>
      </url>
   </cfoutput>
<cfoutput>
</urlset>
</cfoutput>

Just create a file called sitemap.cfm in your blog root and paste the code above.

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?D3646F77-3048-7431-E4A5221514CFFEEE

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
This blog is running version 5.9.003. Contact Blog Owner