Author: Steven Neiland
Published:

Warning: This blog entry was written two or more years ago. Therefore, it may contain broken links, out-dated or misleading content, or information that is just plain wrong. Please read on with caution.

Step 3: Add Dynamic Content

Now that the sitemap is being served by coldfusion we can add to it dynamically. Here I will demonstrate how I add some blog entries to the listing.

<cfsetting enablecfoutputonly="true" showdebugoutput="false">
<cfprocessingdirective pageencoding="utf-8">
<cfquery name="demo" datasource="mydatasource">
select
url, dateupdated
from blog
limit 5
</cfquery>
<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
>

<url>
<loc>http://www.neiland.net/</loc>
      <lastmod>2011-03-05</lastmod>
      <changefreq>daily</changefreq>
      <priority>1</priority>
</url>
<url>
<loc>http://www.neiland.net/blog/</loc>
      <lastmod>2011-03-05</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.8</priority>
</url>
<cfloop query="demo">
<url>
<loc>http://www.neiland.net/blog/#demo.url#/</loc>
       <lastmod>#dateFormat(demo.dateupdated,"yyyy-mm-dd")#</lastmod>
<changefreq>never</changefreq>
       <priority>0.5</priority>
</url>
</cfloop>
</urlset>
</cfoutput>

As you can see its a simple matter of getting some data and outputting it. Note the use of dateformat to output a valid date for the lastmod child node. Finally there is one last step we can do.

1 2 3 4

What Do You Think?

Reader Comments

David Tananbaum's Gravatar
David Tananbaum
Friday, December 18, 2015 at 3:37:43 PM EST

Are you available for assignment to redefine out sitemap code for the website as listed above?

David Tananbaum, Pesident
AtPrime media Services

Post a Comment

Comment Etiquette:

  • Please keep comments on-topic.
  • Please do not post unrelated questions or large chunks of code.
  • Please do not engage in flaming/abusive behaviour.
  • Comments that contain or appear to be advertisments, will not be published.
  • Comments that appear to be created for the purpose of linkbuilding to commercial sites will be removed.

We are all adults here so play nice.

*
*



Archives Blog Listing

Tag Listing

Learn CF In A Week

Treehouse

 
Fork me on GitHub