This method will work for all Pages and Mounted Collections (just like Pages view in CP).
- Create a template called
sitemap.html
and add it to yourtheme/layouts/
folder. - Add the following code to the new template
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{{ nav from="/" include_home="true" include_entries="true" exclude="our-team" }}
<url>
<loc>{{ permalink }}</loc>
<lastmod>{{ last_modified format="Y-m-d" }}</lastmod>
<changefreq>monthly</changefreq>
<priority>{{ if url == homepage }}0.8{{ else }}0.5{{ /if }}</priority>
</url>
{{ if children }}
{{ children sort="order" }}
<url>
<loc>{{ permalink }}</loc>
<lastmod>{{ last_modified format="Y-m-d" }}</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
{{ /children }}
{{ /if }}
{{ /nav }}
</urlset>
- Open up
site/settings/routes.yaml
and add the following:
routes:
/sitemap:
template: sitemap
layout: sitemap
content_type: xml
- Visit the page at
http://yourdomain/sitemap
Suggestion: Add the following to the top so the correct xml header would be rendered, too
{{ xml_header }}