Skip to content
  1. Extras
  2. pdoTools
  3. Snippets
  4. pdoSitemap

pdoSitemap

pdoSitemap i a snippet that easily creates sitemaps for search engines (sitemap.xml). The snippet understands the parameters used by the snippet GoogleSitemap (by translation to the native parameters) and can therefore easily replace it.

The main feature is a much higher processing speed compared to the snippet GoogleSitemap. The site bezumkin.ru with 1700 pages increased the generation speed of the sitemap by 12 times from 8.4 seconds down to 0.7.

By default is the check for user permissions disabled. This can easily be remedied by including the parameter &checkPermissions (Note: slows down the generation!):

modx
[[!pdoSitemap?
  &checkPermissions=`list`
]]

The sitemap generation is more effective if resources are excluded from the output rather than to explicit include resources that shall be visible (see examples below).

Options

pdoSitemap accepts all options for pdoTools. Here are some of them:

ParameterDefault valueDescription
&sitemapSchemahttp://www.sitemaps.org/schemas/sitemap/0.9The scheme used for the sitemap.
&forceXML1Force output as XML.
&priorityTVAn optional field that indicates the priority of the resource. The template variable stated here must also be added to the parameter &includeTVs

Templates

  • &tpl

    modx
    @INLINE <url>\n\t
    <loc>[[+url]]</loc>\n\t
    <lastmod>[[+date]]</lastmod>\n\t
    <changefreq>[[+update]]</changefreq>\n\t
    <priority>[[+priority]]</priority>\n
    </url>
  • &tplWrapper

    modx
    @INLINE <?xml version=\"1.0\" encoding=\"[[++modx_charset]]\"?>\n<urlset xmlns=\"[[+schema]]\">\n[[+output]]\n</urlset>

Priority and Change frequency for the resource is mapped based on the date for the last modification of the document:

Time since the last update of the documentPriorityChange frequency
Less than a day ago1.0daily
Over one day but less than a week ago0.75weekly
More than a week ago but less than a month ago0.5weekly
More than a month ago0.25monthly

Instructions how to create a sitemap.xml resource

  1. Create a new document in the root of the site. On the Document tab, select an empty template. Enter the "Title" of the document (your choice) and set the "Resource Alias" to sitemap. Mark the checkboxes "Hide From Menus" and "Published".
  2. Go to the Settings tab and select XML as the "Content Type".
  3. Remove the mark from the checkbox "Rich Text" and save the document.
  4. The "Content" of the document should only be a call to the snippet pdoSitemap (see the examples here below).

Examples

To create a sitemap for the default context, this should be sufficient in the most cases:

modx
[[pdoSitemap]]

Generate sitemap only from certain containers:

modx
[[pdoSitemap?
  &parents=`10`
]]

The extend the example above to also exclude resources with id = 15 and 25, together with their descendants:

modx
[[pdoSitemap?
  &parents=`10,-15,-25`
]]

Change the example above to exclude the resource with id = 25 but include its descendants:

modx
[[pdoSitemap?
  &resources=`-25`
  &parents=`-15,10`
]]

Add another context (catalog) to the example above (if web is the default context):

modx
[[pdoSitemap?
  &resources=`-25`
  &parents=`-15,10`
  &context=`web,catalog`
]]

This call forces the http schema of the URL:s to https:

modx
[[pdoSitemap?
  &resources=`-25`
  &parents=`-15,10`
  &context=`web,catalog`
  &scheme=`https`
]]

This call shows the execution log (remember to change the content type of the resource to HTML):

modx
[[pdoSitemap?
  &resources=`-25`
  &parents=`-15,10`
  &context=`web,catalog`
  &showLog=`1`
  &forceXML=`0`
]]