getResources.Google XML Sitemap
Last updated Nov 27th, 2019 | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$301 per month—let's make that $500!
Learn moreWho needs a special snippet, you can also let getResources do the dirty work of creating an XML sitemap for Google.
We'll be making a couple of items:
- a mess of TVs to hold Sitemap data like change frequency, priority, and others.
- a resource for our sitemap.xml
- a tpl chunk for getResources
The TV's¶
First create a category for your TV's, let's call it "Search Tools", it will help organize them on the Template Variables tab. Also when creating each TV make sure to allow it access to each Template.
Change Frequency - This is used to tell Google how often you expect a page to be updated.
- Name it change-frequency, select the new Search Tools for it's category.
- Next choose input type: DropDown List
- Input Option Values of: always||hourly||daily||weekly||monthly||yearly||never
- I recommend default value of: monthly
Google Sitemap Priority - This is used to tell Google how important each page is. And no, giving them all a value of 1 wont make them index better :)
- Name it google-site-map-priority, select the new Search Tools for it's category.
- Next choose input type: DropDown List
- Input Option Values of: .1||.2|| .3|| .5|| .6|| .7|| .8|| .9|| 1
- I recommend default value of: .5
The Chunk¶
Create a new chunk and call it: google-sitemap-tpl
<url>
<loc>[[~[[+id]]? &scheme=`full`]]</loc>
<lastmod>[[+editedon]]</lastmod>
<priority>[[+tv.google-site-map-priority]]</priority>
<changefreq>[[+tv.change-frequency]]</changefreq>
</url>?
The Page¶
Create a page in the root of your site and name it "sitemap.xml". Check the Hide From Menus box. Set the template to <empty>
. In Page Settings change the content type to xml. Paste in the below code and you should be good to go. When you have saved it, confirm the resource alias field is 'sitemap.xml' and the resource is published.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
[[getResources?
&parents=`0`
&tpl=`google-sitemap-tpl`
&limit=`500`
&sortdir=`DESC`
&includeTVs=`1`
&processTVs=`1`
&depth=`10`
&sortby=`publishedon`
]]
</urlset>
If you have more than 500 resources or more than 10 levels deep, you may want to change the limit and depth properties in the snippet call.
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$301 per month—let's make that $500!
Learn more