Creating a sitemap in ExpressionEngine

Keatch.com

Profile

Nathan Keatch

I’m passionate about designing & building websites & web apps using clean and well written code. In an industry that is ever evolving, it’s essential to stay up to date and on top of new techniques and trends.

When embarking on a new project it’s always my goal to create something that is scaleable and able to grow with my clients business as the web and new technologies evolve.

I work across a wide range of projects including freelancing for agencies and directly with clients. This has allowed me to work on a range of projects from custom CMS’s to full featured web applications.

Back

Creating a sitemap in ExpressionEngine

By Nathan Keatch - 11 Feb 2017

Creating a sitemap in ExpressionEngine is pretty easy but I after talking to a few people it seems to be something a lot of developers turn or 3rd party plugins for. I like to avoid plugins wherever possible purely to make updating and maintaining sites easier.

Creating a dynamic sitemap is not hard to do on your own and it will most certainly help your search engine rank. The basic purpose of a sitemap is tell Google when a page has been added to your site and how often it gets updated so that they can keep info about your site current.


Step1.

Create a new template as an XML document and add the following declaration to tell the file what it is.

<?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">

Step 2.

I like to start by adding any static pages at the top here. It’s always good practice to keep your code neat and logically ordered.

<url>
  <loc>{site_url}/</loc>
  <lastmod>2017-02-11T19:18:31+00:00</lastmod>
  <changefreq>monthly</changefreq>
</url>

<url>	
  <loc>{site_url}/about</loc>
  <lastmod>2017-02-11T19:18:31+00:00</lastmod>
  <changefreq>monthly</changefreq>
</url>

Do that for all your static pages remembering to change the url.

Step 3.

Here’s where we add any dynamic pages by looping through your channel entries. If your url structure follows an index/post pattern, define the index page above the channel:entries loop for that channel.

<url>
  <loc>{site_url}/projects</loc>
  <lastmod>2017-02-11T19:18:31+00:00</lastmod>
  <changefreq>monthly</changefreq>
</url>

{exp:channel:entries channel="projects" status="Open" limit="9000"}
<url>
  <loc>{title_permalink="projects/view"}</loc>
  <lastmod>{edit_date format="%Y-%m-%dT06:00:00+00:00"}</lastmod>
  <changefreq>monthly</changefreq>
</url>
{/exp:channel:entries}

Repeat this for all of your channels - Obviously you’re going to want to change the URL structure to suite your site and the channel specified in the channel entries tag pair.

Step 4.

Make sure you close the urlset with:

</urlset>

That’s it! You’ve created a sitemap without having to resort to a 3rd party add-on. Your completed sitemap should look something like this https://keatch.com/site/sitemap