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.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org
<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>
1<cfsilent>
2<cfsetting enablecfoutputonly="yes" showdebugoutput="no">
3<cfscript>
4 pageObj = createObject("component","Pages").init(application.dsn);
5 qPages = pageObj.getPages();
6</cfscript>
7<?xml version="1.0" encoding="UTF-8"?>
8<cfsavecontent variable="xmlResult">
9 <cfoutput><urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
10 <url>
11 <loc>http://www.#application.qConfig.domain#</loc>
12 <lastmod>#dateFormat(Now(),"yyyy-mm-dd")#</lastmod>
13 <changefreq>daily</changefreq>
14 <priority>0.8</priority>
15 </url>
16 <cfloop query="qPages">
17 <cfif page_type EQ "P">
18 <url>
19 <loc>http://www.#application.qConfig.domain#/#pageObj.getPageLink(qPages.id)#</loc>
20 <lastmod>#dateFormat(modified,"yyyy-mm-dd")#</lastmod>
21 <changefreq>daily</changefreq>
22 <priority>0.8</priority>
23 </url>
24 </cfif>
25 </cfloop>
26 </urlset>
27 </cfoutput>
28</cfsavecontent>
29</cfsilent><cfcontent type="text/xml"><cfoutput>#xmlResult#</cfoutput>
This entry was posted on April 4, 2007 at 10:56 AM and has received 6758 views. Comments 0 |
Print this entry.