RSS Feeds and Sitemaps in Statamic

Posted on Mar 22, 2018.

It's over a year since I wrote this article so some of the information may be a little out of date compared to newer articles.

Statamic is a flat-file content management system built on the Laravel framework.

If you've built a website with Statamic, you'll know that by default, Statamic does not automatically come with RSS feeds or Sitemaps. In this article I will show you how to setup a simple RSS feed and a simple sitemap for your Statamic website.

The first thing you will need is a Statamic site and a theme. Which you'll most likly have if you're reading this article.

First things first, create a new layout, I called mine xml.html, you can call it whatever you like. In that file, just copy and paste the following:

{{ template_content }}

Now we can create two new templates. One for your sitemap and one for your RSS feed.

RSS Feed

This is the code I use for my RSS Feed on my site. You can fill it out with more details if you need to. It's just a really simple template.

{{ xml_header }}
<title>Your Site Name</title>
<link>https://your.site.com</link>
<description>Description of your site</description>
<category>The category of your website</category>

{{ collection:blog paginate="true" as="posts" }}
  {{ posts scope="tag" }}
    <item>
      <title>{{ title }}</title>
      <link>https://your.site.com{{ url }}</link>
      <description>{{ content | striptags }}</description>
      <pubDate>{{ date format="M j, Y" }}</pubDate>
    </item>
  {{ /posts }}
{{ /collection:blog }}

Sitemap

Below is what I use for the sitemap on this site. Again, it's all really basic. All the below sitemap does is get the latest from the blog collection and loops them.

{{ xml_header }}
{{ collection:blog as="posts" }}
	{{ posts scope="tag" }}
		<loc>https://your.site.com{{ url }}</loc>
  	<changefreq>weekly</changefreq>
  	<priority>0.5</priority>
	{{ /posts }}
{{ /collection:blog }}

After you have created the two files, you need to add them to your site/settings/routes.yaml file so they can actually be used. Copy and paste the following into your routes file.

/feed:
  template: xml/feed
  layout: xml
  content_type: xml
/sitemap.xml:
  template: xml/sitemap
  layout: xml
  content_type: xml

After you have copied it into your routes file, it should look something like this.

routes:
  /blog/tags: blog/taxonomies
  /search: search
  /login: auth/login
  /register: auth/register
  /forgot-password: auth/password-forgot
  /reset-password: auth/password-reset
  /feed:
    template: xml/feed
    layout: xml
    content_type: xml
  /sitemap.xml:
    template: xml/sitemap
    layout: xml
    content_type: xml

You should now be able to view your RSS feed and sitemap at the following URLs.

  • RSS Feed: https://your-site.com/feed
  • Sitemap: https://your-site.com/sitemap.xml