Google Sitemap Date Format

Word Count: 341

Our clients use a CMS system that was built in house. Last week I started added the ability to produce a sitemap. One gotcha that I did not realize was the date needs to be in a particular format, the format of your dates should be "yyyy-mm-dd". If you do not put your dates in this format or the long version, you will receive an error when submitting your sitemap. Here is the code we use to generate our sitemap. Basically our getPages() method returns a query object with pages in the system that I want to include in the sitemap. Following the sitemap guidlines I can now just loop through the query and set the url,lastmod,changefreq & priority properties.

<cfsilent>
<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
<cfscript>
   pageObj = createObject("component","Pages").init(application.dsn);
   qPages = pageObj.getPages();
</cfscript>
<?xml version="1.0" encoding="UTF-8"?>   
<cfsavecontent variable="xmlResult">
   <cfoutput><urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
    <url>
       <loc>http://www.#application.qConfig.domain#</loc>
       <lastmod>#dateFormat(Now(),"yyyy-mm-dd")#</lastmod>
       <changefreq>daily</changefreq>
       <priority>0.8</priority>
    </url>
    <cfloop query="qPages">
    <cfif page_type EQ "P">
         <url>
          <loc>http://www.#application.qConfig.domain#/#pageObj.getPageLink(qPages.id)#</loc>
          <lastmod>#dateFormat(modified,"yyyy-mm-dd")#</lastmod>
          <changefreq>daily</changefreq>
           <priority>0.8</priority>
         </url>
      </cfif>
    </cfloop>
   </urlset>
   </cfoutput>
</cfsavecontent>   
</cfsilent><cfcontent type="text/xml"><cfoutput>#xmlResult#</cfoutput>

Comments



Post Your Comment







Show Captcha

If you subscribe, any new posts to this thread will be sent to your email address.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.