ColdFusioning.com
Pronunciation \kold-fy-zhn-ing\ Noun: The actions of one that writes ColdFusion.

Please check out my new site: http://ja.mesbrown.com/

Google and Yahoo Sitemaps

Sitemaps can be one of the more important, but often overlooked, things you can do to help search engines find all the pages in your site. While some people create them by hand or use a 3rd party sitemap generator, I prefer to use ColdFusion to generate them.

The code below has three variables that need to be set in the first three lines. You can use the code after "Other Page" to suit your specific situation especially if you need to list pages in a database.

I used this code to generate the sitemap for My Cool Backgrounds and you can view the sitemap here: http://www.mycoolbackgrounds.com/sitemap.xml. Be warned though, it has almost 10K urls and might take a minute to load.

After you have generated your sitemap, you can submit it to Google Webmaster Tools and Yahoo Site Explorer. They both will accept the same format for the sitemap.

view plain print about
1<cfset request.addy = "http://www.example.com/" />
2<cfset request.root = "/www/example.com/public/" />
3<cfset PageList = "main/about,category,contact" />
4
5<cfset iCount = 1 />
6
7<cfset theXML = XmlNew() />
8<cfset theXML.urlset = XmlElemNew(theXML,"urlset") />
9<cfset theXML.urlset.XmlAttributes.xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" />
10
11<!------------------------------------------------------------------------------------------
12Main Page:
13------------------------------------------------------------------------------------------->

14<cfset theXML.urlset.XmlChildren[iCount] = XmlElemNew(theXML,"url") />
15
16<cfset theXML.urlset.XmlChildren[iCount].loc = XmlElemNew(theXML,"loc") />
17<cfset theXML.urlset.XmlChildren[iCount].loc.XmlText = "#request.addy#" />
18
19<cfset theXML.urlset.XmlChildren[iCount].lastmod = XmlElemNew(theXML,"lastmod") />
20<cfset theXML.urlset.XmlChildren[iCount].lastmod.XmlText = DateFormat(Now(), "YYYY-MM-DD") />
21
22<cfset theXML.urlset.XmlChildren[iCount].changefreq = XmlElemNew(theXML,"changefreq") />
23<cfset theXML.urlset.XmlChildren[iCount].changefreq.XmlText = "daily" />
24
25<cfset theXML.urlset.XmlChildren[iCount].priority = XmlElemNew(theXML,"priority") />
26<cfset theXML.urlset.XmlChildren[iCount].priority.XmlText = ".9" />
27
28<cfset iCount = incrementValue(iCount) />
29
30<!------------------------------------------------------------------------------------------
31Other Pages:
32------------------------------------------------------------------------------------------->

33<cfloop index="txtItem" list="#PageList#">
34<cfset theXML.urlset.XmlChildren[iCount] = XmlElemNew(theXML,"url") />
35
36<cfset theXML.urlset.XmlChildren[iCount].loc = XmlElemNew(theXML,"loc") />
37<cfset theXML.urlset.XmlChildren[iCount].loc.XmlText = "#request.addy##txtItem#/" />
38
39<cfset theXML.urlset.XmlChildren[iCount].lastmod = XmlElemNew(theXML,"lastmod") />
40<cfset theXML.urlset.XmlChildren[iCount].lastmod.XmlText = DateFormat(Now(), "YYYY-MM-DD") />
41
42<cfset theXML.urlset.XmlChildren[iCount].changefreq = XmlElemNew(theXML,"changefreq") />
43<cfset theXML.urlset.XmlChildren[iCount].changefreq.XmlText = "daily" />
44
45<cfset theXML.urlset.XmlChildren[iCount].priority = XmlElemNew(theXML,"priority") />
46<cfset theXML.urlset.XmlChildren[iCount].priority.XmlText = ".8" />
47
48<cfset iCount = incrementValue(iCount) />
49</cfloop>
50
51<cffile action="write" file="#request.root#sitemap.xml" output="#lcase(Trim(theXML))#" />
52<h3>SiteMap Generated</h3>

TweetBacks

Comments

Recent Comments

RSS

Subscribe