Improving SEO With XML Site Mapping
Posted by Tim Stephenson, RaddOnline® on Friday, February 13, 2009
What's an XML Site Map
If you're working on improving SEO for your website, or for one of your client's, you've probably had a need to create an XML site map. An XML site map is a file that lists the URLs in a website. It also allows you to include additional information about each URL, such as the date it was last updated, or how often it changes.
The XML site map is used to help crawlers find certain pages on your site. You can reference it in your robots.txt file or submit it directly to a search engine. Doing this does not ensure that the search engine will index your entire site. It is simply a guide to help the crawler find pages that it might otherwise miss.
Since we frequently use Radiant CMS, I am going to describe the process of generating an XML site map in Radiant. I'll be formatting this for Google, which adheres to Site map Protocol 0.9 as defined by sitemaps.org.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>http://www.example.com/</loc>
<lastmod>2005-01-01</lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
</urlset>
Now that we know how the XML should look, and we know what it is for, let's get started. Luckily, Radiant makes this easy.
Overview
Here's the steps to complete our task.
- Create a new Layout that contains the basics of the XML document.
- Create the Page that will generate the XML when it is requested.
- Create Snippets of Radius code that will loop through the pages in the site and add the URLs to the page.
Creating a New Layout
First things first, lets create the new Layout.
In your Radiant web site, click on the Layouts tab. If you already have a Layout called XML Feed, you're done. Just use it. If you don't, click on the Add Layout button. Name the Layout XML Feed, in the body enter the following:
<r:content />
This tells Radiant to include the content of the page in the Layout. In this case, that's all we need.
Create a New Page for the XML Site Map
Next, click on the Pages tab and create a new Page. In my case, I am making it a child of the home page, and I'm giving it the clever name, XML Site Map. Here's what should be in the page at this point:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
--- Leave this area blank for now. We'll add code shortly.
</urlset>
Be sure to select the XML Feed Layout when you save the Page.
There is a very good example of how to create an HTML site map on the Radiant Wiki. I'll be modifying details of that example from here on to create the XML site map.
Create Snippets to do the Work
Next create a Snippet that uses recursion to loop through all of the pages in the site. Click on the Snippets tab and click on the Add Snippets button. Enter the following code:
<r:children:each>
<r:unless_content part="no-map">
<url>
<loc>http://www.yoursite.com<r:url /></loc>
<lastmod><r:date format="%Y-%m-%d" /></lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
<r:snippet name="xml-sitemap" />
</r:unless_content>
</r:children:each>
Let's go ahead and complete the page to include the Snippet, and then come back for an explanation. Go back to the XML Site Map page we created earlier and modify it to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<r:find url="/">
<r:snippet name="xml-sitemap" />
</r:find>
</urlset>
What's Going On?
I added two lines:
<r:find url="/">
<r:snippet name="xml-sitemap" />
This first line finds the root page in the site, and the second one loads the xml-site map Snippet.
The first line in the Snippet starts a loop that will go through each of the child pages in the site. Since we started with the root page, that means all of the pages. In this case, I don't actually want all of the pages. I want to skip my CSS and a couple of other pages that are not relevant for a site map.
The second line:
<r:unless_content part="no-map">
does just that. In this case, for any page that I don't want included in the map, I've added a Page Part called no-map. To add a no-map Page Part, open any of your Pages and click on the green "+" icon to the right of the tabs. Name it no-map and click Add Part. You don't need to add anything to the Page Part. If the part is present, that page will be ignored in the site map.
The next lines generate the XML for each of the URLs:
<url>
<loc>http://www.raddonline.com<r:url /></loc>
<lastmod><r:date format="%Y-%m-%d" /></lastmod>
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</url>
This segment will be repeated for each page in the site. The <loc> tag contains the URLs. To match the date format in the sample XML, I added the format property to the date tag to get the date formatted as 2009-02-27.
Refactor to Improve Frequency and Priority
You've probably noticed that the change frequency and priority are a bit static. It is unlikely that they should be the same for every page. I'll take care of that next.
<url>
<loc>http://www.raddonline.com<r:url /></loc>
<lastmod><r:date format="%Y-%m-%d" /></lastmod>
<r:if_content part="frequency-priority">
<r:content part="frequency-priority" />
</r:if_content>
<r:unless_content part="frequency-priority">
<changefreq>monthly</changefreq>
<priority>0.8</priority>
</r:unless_content>
</url>
This adds a check for a Page Part named frequency-priority. If it is present, it gets used. If not, it uses the default values from the original version. The last thing to do is to go to a page that should be different, and add a new Page Part named frequency-priority. The content of the Part should look like this:
<changefreq>weekly</changefreq>
<priority>0.9</priority>
Of course the values can be changed to whatever is relevant for that page. That's it. You should now have a page that returns an xml site map to help improve your SEO.

Comments
http://ebdaa.yoo7.com said on Thursday, March 26, 2009:
thank you very much ..
Patrick Berkeley said on Wednesday, April 01, 2009:
Thanks for this. Works really well. I'm wondering if a sitemap generator could be hooked into the Radiant page versioning extension to automatically determine the change frequency and priority?
San francisco webdesign said on Wednesday, January 06, 2010:
As a fellow webdesigner , I'm extremely glad to see that another individual thought to post this topic.
All too many people out there don't understand what all is needed in this field, and I think also we're many times not appreciated enough
or taken for granted. Never the less I'm immensely glad to see that you feel the same way I do , thanks so much for your blog!