Skip to content
mihaisucan edited this page Nov 22, 2010 · 4 revisions

The sitemapFriend snippet for MODx Revolution provides all the functionality you might need for generating site maps for your web site.

Code is based on the GoogleSiteMap snippet by Shaun McCormick.

Installation

Get the sitemapFriend transport package from the MODx extras repository. Or just search for sitemapFriend in the MODx Revolution package manager and install it from there.

Usage examples

Generate an HTML page:
[[!sitemapFriend? &type=`html`]]

Generate the Sitemap XML:
[[!sitemapFriend? &type=`xml`]]

If you want to generate a site map in some custom format, just create your own chunks and tell the snippet to use them. Check the list of available templates below.

It is recommended you install the getCache snippet as well. You can then use sitemapFriend as follows:
[[!getCache? &element=`sitemapFriend` &cacheExpires=`21600` &type=`html`]]

Properties

The snippet is made such that you can generate almost any kind of site map you want. You control the output using the following list of properties:

  • type – The type of site map you want: xml or html. Depending on the choice you make, the other properties change their default value.
  • urlScheme – The URL scheme you want: http, https, full, abs, etc. See the $modx->makeUrl() documentation. Default for HTML type: abs. For XML type, the urlScheme is always full.
  • startId – Build the site map starting from the given resource ID. Default value: 0.
  • contexts – Limit to the specified context(s). If empty, will grab resources from current Context. Defaults to empty, can support a comma-separated list.
  • showDeleted – If true, will include deleted resources. Default is false.
  • showUpublished – If true, will include unpublished resources. Default is false.
  • onlySearchable – If true, will only include searchable resources. Default is true.
  • showHidden – If true, will include resources which are not visible in menus. Default is true.
  • maxDepth – The maximum depth down the tree to grab resources from. If set to empty or 0, will grab all resources.
  • onlyTemplates – A comma-separated list of template IDs to filter by. Will only filter if a value is set.
  • skipTemplates – A comma-separated list of template IDs to skip. Will only filter if a value is set.
  • excludeResources – A comma-separated list of resources to exclude entirely from the site map. Child resources will also be excluded. The resources pointed at by the modx options error_page, site_unavailable_page, unauthorized_page and the site map page itself are always excluded.
  • skipResources – A comma-separated list of resources to hide from the site map. Child resources will NOT be excluded.
  • includeResources – A comma-separated list of resources to always include in the site map, even if the given resource would otherwise be filtered out by the showDeleted, showUnpublished, onlySearchable and showHidden options.
  • excludeChildrenOf – A comma-separated list of resources for which you do not want to have their children included in the site map. Note that the resources you list here will be included, only the children will be skipped.
  • parentTitles – Include parent resource titles in the site map. Default value: false.
  • parentTitlesReversed – If parent resource titles are used, then this tells if the titles should be in a reversed order. Default is false.
  • titleSeparator – If parent resource titles are used, then this tells the titles separator string. The default string is " – ".
  • sortBy – The field to sort the results by. Default value: menuindex.
  • sortDir – The direction to sort in. Default value: ASC.
  • lastmodFormat – Last modification date format. This uses the same format as the PHP date() function. Default for HTML type: “F j, Y, g:i a”. For the XML type the “c” value is always used (ISO 8601 date format).

Templates

The sitemapFriend package comes with a category of chunks. Never edit the existing chunks! If you do so, your changes will be lost when you update the package. Duplicate the chunks you want to change, and then tell the sitemapFriend snippet the names of the new chunks.

The following properties allow you to customize the site map output:

tplItem

The chunk to use for each result item. Default for HTML type: sitemap_html_item. sitemap_xml_item is always used for the XML type.

Available placeholders:

  • parent – Holds the parent resource ID.
  • id – The ID of the resource being processed.
  • url – The URL of the resource.
  • lastmod – The last modification date for the resource.
  • title – Resource title. This can include the title of each parent resource as well, if parentTitles is set to true.
  • items – Holds the site map output for the child resources, if any. This allows you to nest resources in output, like in an HTML site map. See how this is used in the sitemap_html_item chunk.
  • changefreq – Resource change frequency, which is computed based on the last modification date. Available only for XML site maps.
  • priority – Resource priority, again computed based on last modification date. Available only for XML site maps.

Think of this chunk as the HTML <LI> which lists a page in your site. It can have child items as well, wrapped inside a tplContainer.

tplContainer

The chunk to use as a wrapper for the children of a resource folder. Think of this as the UL around the LIs in HTML. This property is never used for the XML type.

Available placeholders:

  • depth – Current resource depth.
  • id – Current resource ID, for which we have generated output.
  • items – The output string that lists the child resources.

tplOuter

The chunk to use as an outer container for the entire site map output. Default for HTML type: sitemap_html_outer. sitemap_xml_outer is always used for the XML type.

Available placeholders:

  • startId – The site map start resource ID.
  • items – The entire site map output string.
Clone this wiki locally