We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28021
    • 13 Posts
    I solved my problem with doing this:

    First: create a snippet, and name it GoogleSiteMap_XML
    Then: create a new template that only contains the snippet call
    Then: create a new document. Content-type XML and assign the Google sitemap template.
      • 17717
      • 433 Posts
      Probably a simple or even stupid question but how do I remove certain URL from the site map, for instance, I have the search results page showing on the site map when it doesn’t need to be there.

      Thanks for any help.

      Lee
        http://www.blend.uk.com | Web Design by Blend
        • 27423
        • 10 Posts
        This may be the wrong way to do this but, I duplicated the template I am using for the search page and named it search and applied it to the search page, then in the snippit call just use all the templates you want to show in the sitemap.  Works but there could be a better way.  Thanks for this code.
          • 13003
          • 18 Posts
          Fixed the site url issue, you no longer need to manually alter the code: GoogleSiteMap_XML

          <?php
          /*  GoogleSiteMap_XML Snippet for MODx
              Michal Till
              `->Based on Ryan Nutt's Google Sitemap snippet for Etomite
                 `->Based on the ListSiteMap snippet by JaredDC
          
          USAGE
          =====
          Use &allowedtemplates to specify templates, that would be included in the sitemap listing. SEPARATE BY COMMA. Don't forget to switch mime type to text/xml. NOTE: &allowed templates may be case sensitive!
          
          EXAMPLE
          =======
          [[GoogleSiteMap_XML? &allowedtemplates=`Site,Article,Homepage`]]
          
          */
            
          //  Overcome single use limitation on functions
          global $MakeMapDefined,$site_url;
          
          if(!function_exists(datediff))
              {
              function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
            /*
              $interval can be:
              yyyy - Number of full years
              q - Number of full quarters
              m - Number of full months
              y - Difference between day numbers
                (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
              d - Number of full days
              w - Number of full weekdays
              ww - Number of full weeks
              h - Number of full hours
              n - Number of full minutes
              s - Number of full seconds (default)
            */
          
            if (!$using_timestamps) {
              $datefrom = strtotime($datefrom, 0);
              $dateto = strtotime($dateto, 0);
            }
            $difference = $dateto - $datefrom; // Difference in seconds
          
            switch($interval) {
          
              case 'yyyy': // Number of full years
          
                $years_difference = floor($difference / 31536000);
                if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
                  $years_difference--;
                }
                if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
                  $years_difference++;
                }
                $datediff = $years_difference;
                break;
          
              case "q": // Number of full quarters
          
                $quarters_difference = floor($difference / 8035200);
                while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                  $months_difference++;
                }
                $quarters_difference--;
                $datediff = $quarters_difference;
                break;
          
              case "m": // Number of full months
          
                $months_difference = floor($difference / 2678400);
                while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                  $months_difference++;
                }
                $months_difference--;
                $datediff = $months_difference;
                break;
          
              case 'y': // Difference between day numbers
          
                $datediff = date("z", $dateto) - date("z", $datefrom);
                break;
          
              case "d": // Number of full days
          
                $datediff = floor($difference / 86400);
                break;
          
              case "w": // Number of full weekdays
          
                $days_difference = floor($difference / 86400);
                $weeks_difference = floor($days_difference / 7); // Complete weeks
                $first_day = date("w", $datefrom);
                $days_remainder = floor($days_difference % 7);
                $odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
                if ($odd_days > 7) { // Sunday
                  $days_remainder--;
                }
                if ($odd_days > 6) { // Saturday
                  $days_remainder--;
                }
                $datediff = ($weeks_difference * 5) + $days_remainder;
                break;
          
              case "ww": // Number of full weeks
          
                $datediff = floor($difference / 604800);
                break;
          
              case "h": // Number of full hours
          
                $datediff = floor($difference / 3600);
                break;
          
              case "n": // Number of full minutes
          
                $datediff = floor($difference / 60);
                break;
          
              default: // Number of full seconds (default)
          
                $datediff = $difference;
                break;
            }
          
            return $datediff;
              }
            }
          if(!isset($MakeMapDefined))
              {
              function MakeMap_snippet($funcEtomite, $listParent,$selfid=-1,$settings)
                  {
          		global $site_url;
          
                  $children = $funcEtomite->getActiveChildren($listParent, "menuindex", "ASC", "id, editedon, template, privateweb ,alias");
                  foreach($children as $child)
                      {
                      $id = $child['id'];
                      if ($selfid!=$id) {
                        $url = $site_url."[~".$id."~]";
                        $date = $child['editedon'];
                        $date = date("Y-m-d", $date);
            
                        // Get the date difference
                        $datediff = datediff("d", $date, date("Y-m-d"));
                        if ($datediff <=1)
                            {
                            $priority = "1.0";
                            $update = "daily";
                            }
                        elseif (($datediff >1) && ($datediff<=7))
                            {
                            $priority = "0.75";
                            $update = "weekly";
                            }
                        elseif (($datediff >7) && ($datediff<=30))
                            {
                            $priority = "0.50";
                            $update = "weekly";
                            }
                        else
                            {
                            $priority = "0.25";
                            $update = "monthly";
                            }
          if (@$settings["allowedtemplates"][$child["template"]]&&$child["privateweb"]==0) {
                        $output .= "<url>\n";
                        $output .= "<loc>$url</loc>\n";
                        $output .= "<lastmod>$date</lastmod>\n";
                        $output .= "<changefreq>$update</changefreq>\n";
                        $output .= "<priority>$priority</priority>\n";
                        $output .= "</url>\n";
            }
                        if ($funcEtomite->getActiveChildren($child['id']))
                            {
                            $output .= MakeMap_snippet($funcEtomite, $child['id'],$selfid,$settings);
                            }
                        }
                      }
                  return $output;
                  }
              $MakeMapDefined = true;
              }
          
          
          $templatesok=array();
          @$allowedtemplates.="";
          $allowedtemplates=",".$allowedtemplates.",";
          $allowedtemplates=preg_replace("/ *, */",",",$allowedtemplates);
          $allowedtemplates=str_replace("'","",$allowedtemplates);
          $sql="select * from ".$this->getFullTableName('site_templates')." where POSITION(CONCAT(',',templatename,',') IN '".$allowedtemplates."')>0";
          $templates=$modx->db->query($sql);
          echo $query;
          while ($template=$modx->db->getRow($templates)) {
            $templatesok[$template["id"]]=true;
          }
          $settings["allowedtemplates"]=$templatesok;
          $out .= "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n";
          $out .= MakeMap_snippet($etomite, 0,$selfid,$settings);
          $out .= "</urlset>";
          return $out;
          ?>
            • 23491 ☆ A M B ☆
            • 1,056 Posts
            We have options! - Updated: Feb, 12th 2007

            Try this quick & easy mod if you’d like the ability to "flag" certain documents to be hidden from the XML Sitemap smiley



            1. Update your GoogleSiteMap_XML Snippet with the following code:
            (No worries, it will not break if you do not have the Template Variable (TV) present yet wink)

            <?php
            /*  GoogleSiteMap_XML Snippet for MODx
                Michal Till
                `->Based on Ryan Nutt's Google Sitemap snippet for Etomite
                   `->Based on the ListSiteMap snippet by JaredDC
                   
                 2007-18-01 [pixelchutes] - Implemented TV option for toggling documents to hide/show in the sitemap :)
                 2007-18-01 [pixelchutes] - Updated to allow @BINDINGS support for TV
                 2007-12-02 [pixelchutes] - Updated XML name space to match Google's base sitemap.xml example (https://www.google.com/webmasters/tools/docs/en/protocol.html)
            
            USAGE
            =====
            Use &allowedtemplates to specify templates, that would be included in the sitemap listing. SEPARATE BY COMMA. Don't forget to switch mime type to text/xml. NOTE: &allowed templates may be case sensitive!
            
            EXAMPLE
            =======
            [[GoogleSiteMap_XML? &allowedtemplates=`Site,Article,Homepage`]]
            
            */
              
            //  Overcome single use limitation on functions
            global $MakeMapDefined,$site_url;
            
            
            if(!function_exists(datediff))
                {
                function datediff($interval, $datefrom, $dateto, $using_timestamps = false) {
              /*
                $interval can be:
                yyyy - Number of full years
                q - Number of full quarters
                m - Number of full months
                y - Difference between day numbers
                  (eg 1st Jan 2004 is "1", the first day. 2nd Feb 2003 is "33". The datediff is "-32".)
                d - Number of full days
                w - Number of full weekdays
                ww - Number of full weeks
                h - Number of full hours
                n - Number of full minutes
                s - Number of full seconds (default)
              */
            
              if (!$using_timestamps) {
                $datefrom = strtotime($datefrom, 0);
                $dateto = strtotime($dateto, 0);
              }
              $difference = $dateto - $datefrom; // Difference in seconds
            
              switch($interval) {
            
                case 'yyyy': // Number of full years
            
                  $years_difference = floor($difference / 31536000);
                  if (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom), date("j", $datefrom), date("Y", $datefrom)+$years_difference) > $dateto) {
                    $years_difference--;
                  }
                  if (mktime(date("H", $dateto), date("i", $dateto), date("s", $dateto), date("n", $dateto), date("j", $dateto), date("Y", $dateto)-($years_difference+1)) > $datefrom) {
                    $years_difference++;
                  }
                  $datediff = $years_difference;
                  break;
            
                case "q": // Number of full quarters
            
                  $quarters_difference = floor($difference / 8035200);
                  while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($quarters_difference*3), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                    $months_difference++;
                  }
                  $quarters_difference--;
                  $datediff = $quarters_difference;
                  break;
            
                case "m": // Number of full months
            
                  $months_difference = floor($difference / 2678400);
                  while (mktime(date("H", $datefrom), date("i", $datefrom), date("s", $datefrom), date("n", $datefrom)+($months_difference), date("j", $dateto), date("Y", $datefrom)) < $dateto) {
                    $months_difference++;
                  }
                  $months_difference--;
                  $datediff = $months_difference;
                  break;
            
                case 'y': // Difference between day numbers
            
                  $datediff = date("z", $dateto) - date("z", $datefrom);
                  break;
            
                case "d": // Number of full days
            
                  $datediff = floor($difference / 86400);
                  break;
            
                case "w": // Number of full weekdays
            
                  $days_difference = floor($difference / 86400);
                  $weeks_difference = floor($days_difference / 7); // Complete weeks
                  $first_day = date("w", $datefrom);
                  $days_remainder = floor($days_difference % 7);
                  $odd_days = $first_day + $days_remainder; // Do we have a Saturday or Sunday in the remainder?
                  if ($odd_days > 7) { // Sunday
                    $days_remainder--;
                  }
                  if ($odd_days > 6) { // Saturday
                    $days_remainder--;
                  }
                  $datediff = ($weeks_difference * 5) + $days_remainder;
                  break;
            
                case "ww": // Number of full weeks
            
                  $datediff = floor($difference / 604800);
                  break;
            
                case "h": // Number of full hours
            
                  $datediff = floor($difference / 3600);
                  break;
            
                case "n": // Number of full minutes
            
                  $datediff = floor($difference / 60);
                  break;
            
                default: // Number of full seconds (default)
            
                  $datediff = $difference;
                  break;
              }
            
              return $datediff;
                }
              }
            if(!isset($MakeMapDefined))
                {
                function MakeMap_snippet($funcEtomite, $listParent,$selfid=-1,$settings)
                    {
            		global $site_url,$modx; // pixelchutes update
            
                    $children = $funcEtomite->getActiveChildren($listParent, "menuindex", "ASC", "id, editedon, template, privateweb ,alias");
                    foreach($children as $child)
                        {
                        $id = $child['id'];
                        if ($selfid!=$id) {
                          $url = $site_url."[~".$id."~]";
                          $date = $child['editedon'];
                          $date = date("Y-m-d", $date);
              
                          // Get the date difference
                          $datediff = datediff("d", $date, date("Y-m-d"));
                          if ($datediff <=1)
                              {
                              $priority = "1.0";
                              $update = "daily";
                              }
                          elseif (($datediff >1) && ($datediff<=7))
                              {
                              $priority = "0.75";
                              $update = "weekly";
                              }
                          elseif (($datediff >7) && ($datediff<=30))
                              {
                              $priority = "0.50";
                              $update = "weekly";
                              }
                          else
                              {
                              $priority = "0.25";
                              $update = "monthly";
                              }
                              
            		$XMLSiteMap_Toggle = $modx->getTemplateVarOutput('XMLSiteMap_Toggle',$id); // pixelchutes update
            		$showDoc = ( is_array($XMLSiteMap_Toggle) ) ? $XMLSiteMap_Toggle[XMLSiteMap_Toggle] : 0; // pixelchutes update
                              
            if (@$settings["allowedtemplates"][$child["template"]] and $child["privateweb"]==0 and (int)$showDoc==0) // pixelchutes update
            {
                          $output .= "<url>\n";
                          $output .= "<loc>$url</loc>\n";
                          $output .= "<lastmod>$date</lastmod>\n";
                          $output .= "<changefreq>$update</changefreq>\n";
                          $output .= "<priority>$priority</priority>\n";
                          $output .= "</url>\n";
              }
                          if ($funcEtomite->getActiveChildren($child['id']))
                              {
                              $output .= MakeMap_snippet($funcEtomite, $child['id'],$selfid,$settings);
                              }
                          }
                        }
                    return $output;
                    }
                $MakeMapDefined = true;
                }
            
            
            $templatesok=array();
            @$allowedtemplates.="";
            $allowedtemplates=",".$allowedtemplates.",";
            $allowedtemplates=preg_replace("/ *, */",",",$allowedtemplates);
            $allowedtemplates=str_replace("'","",$allowedtemplates);
            $sql="select * from ".$this->getFullTableName('site_templates')." where POSITION(CONCAT(',',templatename,',') IN '".$allowedtemplates."')>0";
            $templates=$modx->db->query($sql);
            echo $query;
            while ($template=$modx->db->getRow($templates)) {
              $templatesok[$template["id"]]=true;
            }
            $settings["allowedtemplates"]=$templatesok;
            $out .= '<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'."\n";
            $out .= MakeMap_snippet($etomite, 0,$selfid,$settings);
            $out .= "</urlset>";
            return $out;
            ?>
            


            2. Add the XMLSiteMap_Toggle TV:
            (Don’t forget to assign it to your templates...assign to all if you’re uncertain.)

            Variable Name: XMLSiteMap_Toggle
            Caption: Include in XML Sitemap?
            Input Type: DropDown List Menu
            Input Option Values: Mimic parent, else Yes==@INHERIT||Yes, Include==0||No, Keep Hidden==1
            Default Value: @INHERIT

            Example:


            Enjoy! wink

            NOTE: This is great for taking documents out of your dynamic XML Sitemap, such as 404.html, conversion pages (e.g. thank_you.html), Google/Yahoo Verification pages, etc

              Mike Reid - www.pixelchutes.com
              MODx Ambassador / Contributor
              [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
              ________________________________
              Where every pixel matters.
              • 1932
              • 137 Posts
              Sweet, thanks. I installed and excluded my 404 and thankyou pages; seems to be working great for me. cool

              I saw you added: xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd"

              Probably a good idea.
                • 23491 ☆ A M B ☆
                • 1,056 Posts
                We’ll see wink ...get the mod on Page 1 of this thread

                ...Just got done implementing on a few other sites, and it’s working like a champ. No more manual, sitemap.xml generation/editting for me smiley

                NOTE: Coupled with the SEO Strict FURLs plugin, these go very nicely together giving a lot of control over the output of your XML Sitemaps. I love it.

                UPDATED! My modification Now supports @BINDING! Please update TV, Snippet, and any pages/containers needed!
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 24981
                  • 109 Posts
                  The Snippet appears to hide any any pages that are contained in Unpublished containers.

                  For example, in my site, its hiding all the blog items because these are displayed via Ditto.

                  Richard
                    • 23491 ☆ A M B ☆
                    • 1,056 Posts
                    Quote from: ricardosanX at Jan 24, 2007, 04:07 AM

                    The Snippet appears to hide any any pages that are contained in Unpublished containers.

                    For example, in my site, its hiding all the blog items because these are displayed via Ditto.

                    Richard

                    Please see this post to get you in the right direction: http://modxcms.com/forums/index.php/topic,5754.msg76378.html#msg76378
                      Mike Reid - www.pixelchutes.com
                      MODx Ambassador / Contributor
                      [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                      ________________________________
                      Where every pixel matters.
                      • 23491 ☆ A M B ☆
                      • 1,056 Posts
                      Quote from: ApoXX at Jan 18, 2007, 02:54 PM

                      Sweet, thanks. I installed and excluded my 404 and thankyou pages; seems to be working great for me. cool

                      I saw you added: xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/09/sitemap.xsd"

                      Probably a good idea.

                      I have updated the snippet code found here. Nothing big, but thought the XMLNS should match that of Google’s basic sitemap.xml example as seen here: https://www.google.com/webmasters/tools/docs/en/protocol.html

                      ...in other words, I removed reference to sitemaps.org, and replaced with google...
                        Mike Reid - www.pixelchutes.com
                        MODx Ambassador / Contributor
                        [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                        ________________________________
                        Where every pixel matters.