We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16932
    • 31 Posts
    Dear all,

    On one of my websites i made a sitemap using: http://modx.com/extras/package/sitemap
    Error / sitemap: http://www.kiom.nl/sitemap.xml.html
    Suddenly it's not working anymore. Anybody have a clue?

    Your help is appreciated!

    Kind regards,

    Lennard
      • 9995
      • 1,613 Posts
      The source of the page looks weird.
      Did you use a snippet? and did you try to call it cached or uncached [[ or [!

      My sitemap.xml the simple way (looks like you use the same one smiley
      Missing ?> ?

      On your text/xml page:
      [!Sitemap? &format=`sp`!]


      Sitemap Snippet:
      <?php
      /**
       * sitemap
       * 
       * Outputs a machine readable site map for search engines and robots
       *
       * @category 	snippet
       * @version 	1.0.9
       * @license 	LGPL
       * @author		Grzegorz Adamiak [grad], ncrossland
       * @internal	@modx_category Navigation
       */
       
       
      /*
      ==================================================
      	sitemap
      ==================================================
      
      Outputs a machine readable site map for search
      engines and robots. Supports the following
      formats:
      
      - Sitemap Protocol used by Google Sitemaps
        (http://www.google.com/webmasters/sitemaps/)
      
      - URL list in text format
        (e.g. Yahoo! submission)
      
      
      History:
      # 1.0.9
      - update metadata format for use in ModX 1.0.x installer
      # 1.0.8
      - excludeTemplates can now also be specified as a template ID instead of template name. 
        Useful if you change the names of your templates frequently. (ncrossland)
        e.g. &excludeTemplates=`myTemplateName,3,4`
      # 1.0.7
      - Unpublished and deleted documents were showing up in the sitemap. Even though they could not be viewed, 
        they were showing up as broken links to search engines. (ncrossland)
      # 1.0.6
      - Add optional parameter (excludeWeblinks) to exclude weblinks from the sitemap, since they often point to external
        sites (which don't belong on your sitemap), or redirecting to other internal pages (which are already
        in the sitemap). Google Webmaster Tools generates warnings for excessive redirects.	
        Default is false - e.g. default behaviour remains unchanged. (ncrossland)
      # 1.0.5
      - Modification about non searchable documents, as suggested by forum user JayBee
        (http://modxcms.com/forums/index.php/topic,5754.msg99895.html#msg99895)
      # 1.0.4 (By Bert Catsburg, [email protected])
      - Added display option 'ulli'. 
        An <ul><li> list of all published documents.
      # 1.0.3
      - Added ability to specify the XSL URL - you don't always need one and it 
        seems to create a lot of support confusion!
        It is now a parameter (&xsl=``) which can take either an alias or a doc ID (ncrossland)
      - Modifications suggested by forum users Grad and Picachu incorporated
        (http://modxcms.com/forums/index.php/topic,5754.60.html)
      # 1.0.2
      - Reworked fetching of template variable value to
        get INHERITED value.
      # 1.0.1
      - Reworked fetching of template variable value,
        now it gets computed value instead of nominal;
        however, still not the inherited value.
      # 1.0
      - First public release.
      
      TODO:
      - provide output for ROR
      --------------------------------------------------
      */
      
      /* Parameters
      ----------------------------------------------- */
      
      # $startid [ int ]
      # Id of the 'root' document from which the sitemap
      # starts.
      # Default: 0
      
      $startid = (isset($startid)) ? $startid : 0;
      
      # $format [ sp | txt | ror ]
      # Which format of sitemap to use:
      # - sp <- Sitemap Protocol used by Google
      # - txt <- text file with list of URLs
      # TODO - ror <- Resource Of Resources
      # Default: sp
      
      $format = (isset($format) && ($format != 'ror')) ? $format : 'sp';
      
      # $priority [ str ]
      # Name of TV which sets the relative priority of
      # the document. If there is no such TV, this
      # parameter will not be used.
      # Default: sitemap_priority
      
      $priority = (isset($priority)) ? $priority : 'sitemap_priority';
      
      # $changefreq [ str ]
      # Name of TV which sets the change frequency. If
      # there is no such TV this parameter will not be
      # used.
      # Default: sitemap_changefreq
      
      $changefreq = (isset($changefreq)) ? $changefreq : 'sitemap_changefreq';
      
      # $excludeTemplates [ str ]
      # Documents based on which templates should not be
      # included in the sitemap. Comma separated list
      # with names of templates.
      # Default: empty
      
      $excludeTemplates = (isset($excludeTemplates)) ? $excludeTemplates : array();
      
      # $excludeTV [ str ]
      # Name of TV (boolean type) which sets document
      # exclusion form sitemap. If there is no such TV
      # this parameter will not be used.
      # Default: 'sitemap_exclude'
      
      $excludeTV = (isset($excludeTV)) ? $excludeTV : 'sitemap_exclude';
      
      # $xsl [ str ] 
      # URL to the XSL style sheet
      # or
      # $xsl [ int ]
      # doc ID of the XSL style sheet
      
      $xsl = (isset($xsl)) ? $xsl : '';
      if (is_numeric($xsl)) { $xsl = $modx->makeUrl($xsl); }
      
      
      # $excludeWeblinks [ bool ]
      # Should weblinks be excluded?
      # You may not want to include links to external sites in your sitemap,
      # and Google gives warnings about multiple redirects to pages 
      # within your site.
      # Default: false
      $excludeWeblinks = (isset($excludeWeblinks)) ? $excludeWeblinks : false;
      
      
      /* End parameters
      ----------------------------------------------- */
      
      # get list of documents
      # ---------------------------------------------
      $docs = getDocs($modx,$startid,$priority,$changefreq,$excludeTV);
      
      
      # filter out documents by template or TV
      # ---------------------------------------------
      // get all templates
      $select = $modx->db->select("id, templatename", $modx->getFullTableName('site_templates'));
      while ($query = $modx->db->getRow($select)) {
      	$allTemplates[$query['id']] = $query['templatename'];
      }
      
      $remainingTemplates = $allTemplates;
      
      // get templates to exclude, and remove them from the all templates list
      if (!empty ($excludeTemplates)) {
      	
      	$excludeTemplates = explode(",", $excludeTemplates);	
      	
      	// Loop through each template we want to exclude
      	foreach ($excludeTemplates as $template) {
      		$template = trim($template);
      		
      		// If it's numeric, assume it's an ID, and remove directly from the $allTemplates array
      		if (is_numeric($template) && isset($remainingTemplates[$template])) {
      			unset($remainingTemplates[$template]);
      		} else if (trim($template) && in_array($template, $remainingTemplates)) { // If it's text, and not empty, assume it's a template name
      			unset($remainingTemplates[array_search($template, $remainingTemplates)]);			
      		}
      	} // end foreach
      }
      
      $output= array();
      // filter out documents which shouldn't be included
      foreach ($docs as $doc)
      {
      	if (isset($remainingTemplates[$doc['template']]) && !$doc[$excludeTV] && $doc['published'] && $doc['template']!=0 && $doc['searchable']) {
      		if (!$excludeWeblinks || ($excludeWeblinks && $doc['type'] != 'reference')) {
      			$output[] = $doc;		
      		}
      	}
      }
      $docs = $output;
      unset ($output, $allTemplates, $excludeTemplates);
      
      
      # build sitemap in specified format
      # ---------------------------------------------
      
      switch ($format)
      {
      	// Next case added in version 1.0.4
      	case 'ulli': // UL List
      		$output .= "<ul class=\"sitemap\">\n";
      		// TODO: Sort the array on Menu Index
      		// TODO: Make a nested ul-li based on the levels in the document tree.
      		foreach ($docs as $doc)
      		{
      			$s  = "  <li class=\"sitemap\">";
      			$s .= "<a href=\"[(site_url)][~" . $doc['id'] . "~]\" class=\"sitemap\">" . $doc['pagetitle'] . "</a>";
      			$s .= "</li>\n";
      			$output .= $s;
      		} // end foreach
      		$output .= "</ul>\n";
      		break;
      		
      	case 'txt': // plain text list of URLs
      
      		foreach ($docs as $doc)
      		{
      			$url = '[(site_url)][~'.$doc['id'].'~]';
      
      			$output .= $url."\n";
      		} // end foreach
      		break;
      
      	case 'ror': // TODO
      	default: // Sitemap Protocol
      
      	
      	$output = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
      	if ($xsl != '') {
      		$output .='<?xml-stylesheet type="text/xsl" href="'.$xsl.'"?>'."\n";
      	}
      	$output .='<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
      	
      	
      	foreach ($docs as $doc)	{
      		$url = '[(site_url)][~'.$doc['id'].'~]';
      		$date = $doc['editedon'];
      		$date = date("Y-m-d", $date);
      		$docPriority = ($doc[$priority]) ? $doc[$priority] : 0; // false if TV doesn't exist
      		$docChangefreq = ($doc[$changefreq]) ? $doc[$changefreq] : 0; // false if TV doesn't exist
      
      		$output .= "\t".'<url>'."\n";
      		$output .= "\t\t".'<loc>'.$url.'</loc>'."\n";
      		$output .= "\t\t".'<lastmod>'.$date.'</lastmod>'."\n";
      		$output .= ($docPriority) ? ("\t\t".'<priority>'.$docPriority.'</priority>'."\n") : ''; // don't output anything if TV doesn't exist
      		$output .= ($docChangefreq) ? ("\t\t".'<changefreq>'.$docChangefreq.'</changefreq>'."\n") : ''; // don't output anything if TV doesn't exist
      		$output .= "\t".'</url>'."\n";
      	} // end foreach
      	$output .= '</urlset>';
      
      } // end switch
      
      return $output;
      
      # functions
      # ---------------------------------------------
      
      # gets (inherited) value of template variable
      function getTV($modx,$docid,$doctv)
      {
      /* apparently in 0.9.2.1 the getTemplateVarOutput function doesn't work as expected and doesn't return INHERITED value; this is probably to be fixed for next release; see http://modxcms.com/bugs/task/464
      	$output = $modx->getTemplateVarOutput($tv,$docid);
      	return $output[$tv];
      */
      	
      	while ($pid = $modx->getDocument($docid,'parent'))
      	{
      		$tv = $modx->getTemplateVar($doctv,'*',$docid);
      		if (($tv['value'] && substr($tv['value'],0,8) != '@INHERIT') or !$tv['value']) // tv default value is overriden (including empty)
      		{
      			$output = $tv['value'];
      			break;
      		}
      		else // there is no parent with default value overriden 
      		{
      			$output = trim(substr($tv['value'],8));
      		}
      		$docid = $pid['parent']; // move up one document in document tree
      	} // end while
      	
      	return $output;
      }
      
      # gets list of published documents with properties
      function getDocs($modx,$startid,$priority,$changefreq,$excludeTV)
      {
      	// get children documents
      	$docs = $modx->getActiveChildren($startid,'menuindex','asc','id,editedon,template,published,searchable,pagetitle,type'); 
      	// add sub-children to the list
      	foreach ($docs as $key => $doc)
      	{
      		$id = $doc['id'];
      		$docs[$key][$priority] = getTV($modx,$id,$priority); // add priority property
      		$docs[$key][$changefreq] = getTV($modx,$id,$changefreq); // add changefreq property
      		$docs[$key][$excludeTV] = getTV($modx,$id,$excludeTV); // add excludeTV property
      		
      		if ($modx->getActiveChildren($id))
      			$docs = array_merge($docs, getDocs($modx,$id,$priority,$changefreq,$excludeTV));
      	} // end foreach
      	return $docs;
      }
      ?>

        Evolution user, I like the back-end speed and simplicity smiley
        • 16932
        • 31 Posts
        Hi fourroses666,

        Thank you for your quick reply.
        Now i get a different error: http://www.kiom.nl/sitemap.xml.html

        I did like you said:

        I have an xml page called sitemap.xml and put on there [!Sitemap? &format=`sp`!]
        For the template i used a blank template. It's not cachable and and empty cash is off.

        I made a snippet called "Sitemap" and put your code in there.

        Can you see what's wrong?

        Kind regards,

        Lennard
          • 9995
          • 1,613 Posts
          I see error, you prolly upgraded to 1.0.14

          You need to go to your manager > config > and reset the paths on the 3rd and 4th tab somewhere

          #EDIT

          ohh, I see your site works, just the snippet isn't working, hmm

          Tomorrow I can give a other solution I always use for sitemaps!
          It is posted somewhere on the forums too, really need to go now [ed. note: fourroses666 last edited this post 12 years, 3 months ago.]
            Evolution user, I like the back-end speed and simplicity smiley
            • 16932
            • 31 Posts
            Hi fourroses666,

            I deleted everyting and built it up again like you said. It's working again!
            Thanks so mucht for your help and script! You're a legend!!!!
            What's your website?

            Kind regards,

            Lennard
              • 16932
              • 31 Posts
              graffx.nl ah en je komt ook uit NL hahah. Thanks!
                • 9995
                • 1,613 Posts
                Klopt smiley

                Good to hear it works.

                Downside from that script is you can't remove resources (pages) from your sitemap.xml, only templates.
                Pages like disclaimer, privacy, page not found don't really belong in the sitemap.

                Here is an example of sitemap.xml how I do it:

                - New resource: alias: sitemap.xml / template: blank / text/html / uncheck all checkboxes except last one (clear cache)
                - Save the resource and then add: content: {{sitemap-xml}} (no <p></p> tags!)

                Chunk sitemap-xml: (filter = remove id 7 and 8 from the sitemap)
                <?xml version="1.0" encoding="UTF-8"?>
                <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
                [[Ditto? 
                &id=`xmlsitemap` 
                &startID=`0` 
                &depth=`0` 
                &showPublishedOnly=`1` 
                &showInMenuOnly=`0` 
                &tpl=`sitemap-xml-row` 
                &tplFirst=`sitemap-xml-row-first`
                &dateSource=`editedon` 
                &dateFormat=`%Y-%m-%d` 
                &orderBy=`id ASC, menuindex ASC, pagetitle ASC` 
                &filter=`id,7,2|id,8,2`
                ]]
                </urlset>


                Chunk sitemap-xml-row:
                <url>
                    <loc>[(site_url)][~[+id+]~]</loc>
                    <lastmod>[+date+]</lastmod>
                    <priority>0.5</priority>
                    <changefreq>daily</changefreq>
                </url>


                Chunk sitemap-xml-row-first: (needs a blank line / enter on the bottom of the code)
                <url>
                    <loc>[(site_url)]</loc>
                    <lastmod>[+date+]</lastmod>
                    <priority>1</priority>
                    <changefreq>daily</changefreq>
                </url>
                
                



                Usefull to add a canonical link against duplicate content in your <head> section: (newer versions of modx)
                <link rel="canonical" href="[[if? &is=`[*id*]:is:1` &then=`[(site_url)]` &else=`[(site_url)][~[*id*]~]`]]" />


                This can be done even more extended bij building a SEO tab with mm_rules and add a checkbox for adding or removing the page from the sitemap, and use a priority dropdown.
                  Evolution user, I like the back-end speed and simplicity smiley
                  • 20413
                  • 2,877 Posts
                  The above snippet and solution is great. Here's another old snippet I've used

                  Duh! It's the same snippet... got confused when I read you couldn't exclude individual resources... laugh You can by using a TV!?

                  Quote from: fourroses666 at Jun 19, 2014, 05:56 AM

                  Downside from that script is you can't remove resources (pages) from your sitemap.xml, only templates.

                  Create sitemap.xml (alias+resource type text/xml)
                  [!SiteMap? &format=`sp` &excludeTemplates=`area51, blank, hidden` &excludeTV=`sitemap_exclude` &priority=`sitemap_priority` &changefreq=`sitemap_changefreq` &excludeWeblinks=`true`!]
                  /* Parameters
                  ----------------------------------------------- */
                  
                  # $startid [ int ]
                  # Id of the 'root' document from which the sitemap
                  # starts.
                  # Default: 0
                  
                  $startid = (isset($startid)) ? $startid : 0;
                  
                  # $format [ sp | txt | ror ]
                  # Which format of sitemap to use:
                  # - sp <- Sitemap Protocol used by Google
                  # - txt <- text file with list of URLs
                  # TODO - ror <- Resource Of Resources
                  # Default: sp
                  
                  $format = (isset($format) && ($format != 'ror')) ? $format : 'sp';
                  
                  # $priority [ str ]
                  # Name of TV which sets the relative priority of
                  # the document. If there is no such TV, this
                  # parameter will not be used.
                  # Default: sitemap_priority
                  
                  $priority = (isset($priority)) ? $priority : 'sitemap_priority';
                  
                  # $changefreq [ str ]
                  # Name of TV which sets the change frequency. If
                  # there is no such TV this parameter will not be
                  # used.
                  # Default: sitemap_changefreq
                  
                  $changefreq = (isset($changefreq)) ? $changefreq : 'sitemap_changefreq';
                  
                  # $excludeTemplates [ str ]
                  # Documents based on which templates should not be
                  # included in the sitemap. Comma separated list
                  # with names of templates.
                  # Default: empty
                  
                  $excludeTemplates = (isset($excludeTemplates)) ? $excludeTemplates : array();
                  
                  # $excludeTV [ str ]
                  # Name of TV (boolean type) which sets document
                  # exclusion form sitemap. If there is no such TV
                  # this parameter will not be used.
                  # Default: 'sitemap_exclude'
                  
                  $excludeTV = (isset($excludeTV)) ? $excludeTV : 'sitemap_exclude';
                  
                  # $xsl [ str ] 
                  # URL to the XSL style sheet
                  # or
                  # $xsl [ int ]
                  # doc ID of the XSL style sheet
                  
                  $xsl = (isset($xsl)) ? $xsl : '';
                  if (is_numeric($xsl)) { $xsl = $modx->makeUrl($xsl); }
                  
                  
                  # $excludeWeblinks [ bool ]
                  # Should weblinks be excluded?
                  # You may not want to include links to external sites in your sitemap,
                  # and Google gives warnings about multiple redirects to pages 
                  # within your site.
                  # Default: false
                  $excludeWeblinks = (isset($excludeWeblinks)) ? $excludeWeblinks : false;
                  
                  
                  /* End parameters
                  ----------------------------------------------- */

                  sitemap_exclude --> dropdown list menu
                  Include==0||Exclude==1
                  default value: 1

                  sitemap_priority --> dropdown list menu
                  5==1.0||4==0.7||3==0.5||2==0.3||1==0.0
                  default value: 0.5

                  sitemap_changefreq --> dropdown list menu
                  Always==always||Hourly==hourly||Daily==daily||Weekly==weekly||Monthly==monthly||Yearly==yearly||Never==never
                  default value: monthly
                  [ed. note: mrhaw last edited this post 12 years, 3 months ago.]
                    @hawproductions | http://mrhaw.com/

                    Infograph: MODX Advanced Install in 7 steps:
                    http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                    Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                    http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                    • 9995
                    • 1,613 Posts
                    Thanks for sharing Haw, gona dig into that.

                    I have a couple of SEO projects and added some custom SEO tab for meta description, keywords, custom title etc.
                    This will fit in very good.

                    //
                    Should be great if there would be an EVO SEO install package with this stuff.
                    My wish is still that EVO has these kind of packages and we can install it with just one click.
                      Evolution user, I like the back-end speed and simplicity smiley
                      • 20413
                      • 2,877 Posts
                      Quote from: fourroses666 at Jun 19, 2014, 09:12 AM

                      Should be great if there would be an EVO SEO install package with this stuff.
                      My wish is still that EVO has these kind of packages and we can install it with just one click.

                      Besides Jako's PackageManager https://github.com/Jako/PackageManager
                      You can always set up your own installers
                      https://forums.modx.com/index.php/topic,47933.msg281353.html#msg281353 wink

                      // For REVO users: Jeroen Kenters has a video tutorial: "MODX OnElementNotFound tutorial"
                      https://www.youtube.com/watch?v=b7arN1pnGwA

                      Gist code: https://gist.github.com/jkenters/10651723

                      Awesome plugin.
                        @hawproductions | http://mrhaw.com/

                        Infograph: MODX Advanced Install in 7 steps:
                        http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                        Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                        http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower