Skip to content
  1. Extras
  2. Localizator3
  3. Sitemap

Sitemap ​

The getLocalizedSitemap snippet builds an XML map from published, non-deleted resources with searchable = 1 and active languages. The output contains loc, xhtml:link, and x-default; lastmod appears only for resources with a non-empty editedon.

Parameters ​

NameDefaultDescription
parents0Parent IDs, comma-separated. Empty string and null also become 0. Listed IDs are included, not only their children
depth10getChildIds depth for each parent. 0 and negative values add no children. Children come from the current context
excludeIdsemptyIDs to exclude, comma-separated
scheme0Passed to makeLocalizedUrl with fullUrl = true. Path via makeUrl with -1. Values 1 and 2 replace the protocol
onlyWithLocalizationNoOnly resources with an active localization row (active = 1). Links use languages from those rows; the default language is added first when missing

loc and x-default point to the URL of the language whose key equals localizator3_default_language. If the key is empty or does not match, the first alternate is used.

The hreflang value comes from cultureKey, otherwise from key. For the full language set, languages are ordered by rank, then by id. With onlyWithLocalization, the order follows the localization query and the default language is placed first.

Usage ​

fenom
{'!getLocalizedSitemap' | snippet : [
  'parents' => '1',
  'depth' => 5,
]}
modx
[[!getLocalizedSitemap?
  &parents=`1`
  &depth=`5`
]]

Sample response:

xml
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://site.example/page.html</loc>
    <xhtml:link rel="alternate" hreflang="ru" href="https://site.example/page.html"/>
    <xhtml:link rel="alternate" hreflang="en" href="https://en.site.example/page.html"/>
    <xhtml:link rel="alternate" hreflang="x-default" href="https://site.example/page.html"/>
  </url>
</urlset>

The lastmod tag is added only for resources with a non-empty editedon.

Serve the result as an XML page or a resource of type text/xml. The type is set by the resource or the web server, not by the package.