We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35873
    • 2 Posts
    We have a blog, as well as a few client blogs, that we built in MODX. Does anyone know if there is a plugin or other way to have MODX ping Google whenever a new article is posted? There is a checkbox in the WordPress, I believe, that allows you to do that as part of a standard template. The results are pretty amazing, with Google crawling the site within 2-3 hours of the new post.

    If there is a way to do that in MODX as well, that would be huge. If not, MODX is at a huge disadvantage in the SEO game.

    Thanks to all who reply...
      • 34616
      • 14 Posts
      I’d just add the url on google’s site.

      http://www.google.com/addurl/?continue=/addurl

      I’m sure it’s similar way WordPress does for you.
        • 34193
        • 330 Posts
        I assume by notify google you mean ping sitemap similar to this function here.

        http://www.gidnetwork.com/b-54.html

        If so I think this would be a good addition and am looking at a way to implement it in modx now, shouldn’t be too hard just need to run a plugin in docSave and setup a template variable, check it in the code and run the code on the link above refering to a page which was generated using the GoogleSiteMap snippet.
          • 35873
          • 2 Posts
          Yes! That would be huge. It’s little holes like this that sometimes make our clients unsure about modx. But I figured there had to be a simple solution. If you wouldn’t mind keeping me updated on your progress, that would be great. And let me know if we can help you out with anything.
            • 34616
            • 14 Posts
            Quote from: peteedley at Jul 29, 2011, 09:39 AM

            I assume by notify google you mean ping sitemap similar to this function here.

            http://www.gidnetwork.com/b-54.html

            If so I think this would be a good addition and am looking at a way to implement it in modx now, shouldn’t be too hard just need to run a plugin in docSave and setup a template variable, check it in the code and run the code on the link above refering to a page which was generated using the GoogleSiteMap snippet.

            So how come you don’t try adding GoogleSiteMap from the package management. Then create a snippet using that code you linked.
              • 34193
              • 330 Posts
              OK here is what I have so far, the problem I have is figuring out if google is responding to it. For this to work you need furl’s on.

              1) Download the GoogleSiteMap snippet from the package manager.
              2) Setup up a document with
              a)Published
              b)hidden from menus
              c)no template
              d)Content Type (this is under Page Settings) needs to be XML
              e)in the content box the following [[GoogleSiteMap]]
              f)and alias of sitemap
              This should create a site map in xml format that google will accept.
              3) submit the sitemap to google using http://www.google.com/webmasters/ Not needed unless you want to.
              4) setup a template variable as follows
              name = NotifyGoogle
              input type = checkbox
              input options values = ==true
              default value = false
              make sure all templates have access to it

              5)create a plugin called PingGoogleSiteMap
              6) paste in the following code
              <?php
              function pingGoogleSitemaps( $url_xml )
              {
                 $status = 0;
                 $google = 'www.google.com';
                 if( $fp=@fsockopen($google, 80) )
                 {
                    $req =  'GET /webmasters/sitemaps/ping?sitemap=' .
                            urlencode( $url_xml ) . " HTTP/1.1\r\n" .
                            "Host: $google\r\n" .
                            "User-Agent: Mozilla/5.0 (compatible; " .
                            PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" .
                            "Connection: Close\r\n\r\n";
                    fwrite( $fp, $req );
                    while( !feof($fp) )
                    {
                       if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m) )
                       {
                          $status = intval( $m[1] );
                          break;
                       }
                    }
                    fclose( $fp );
                 }
                 return( $status );
              }
              
              $notify = false;
              
              $eventName = $modx->event->name;
              switch($eventName) {
                  case 'OnDocFormSave':
                      if ($resource->published==1 && $resource->getTVValue('NotifyGoogle')){
                          $notify = true;
                      }
                      else {
                          $notify = false;
                      }
                      break;
                  case 'OnDocPublished':
                      if ($resource->getTVValue('NotifyGoogle')){
                          $notify = true; 
                      }
                      else {
                          $notify = false;
                      }
                      break;
              }
              
              if ($notify) {
                  $url_xml = $modx->config['site_url'].'/sitemap.xml';
                  $returncode = pingGoogleSitemaps( $url_xml );
                  if (!$returncode == 200) {
                       $modx->log(modX::LOG_LEVEL_DEBUG, 'There was an error connecting to the google server it returned the following code '.$returncode);
                  } 
              }

              7)under the system events tab select both
              OnDocFormSave
              OnDocPublish

              Now all you have to do when you create a doc is set the template variable under the template variables tab and it should then ping google sitemaps for an update.

              A few things still to sort once we know this bit works
              1) Clear the template variable so that future updates won’t ping unless we specifically tell it to
              2) Move the TV to the main editing page so it’s easier to use
              3) create a package of all this which I will need help with since I have never done that

              So try it as I say as far as I can tell it works. If anyone spots any issues here at all please let me know.
                • 34193
                • 330 Posts
                OK after further reading on this at http://www.arnebrachhold.de/2006/04/07/google-sitemaps-faq-sitemap-issues-errors-and-problems/ it seems step 3 isn’t needed unless you want to keep stats.
                  • 1841
                  • 141 Posts
                  Wordpress actually uses a service they built called http://pingomatic.com/ and it’s the reason why blog posts can show up in Google within seconds of publishing it.

                  The most effective method of what you are trying to achieve would be to use this API if possible.
                    • 34193
                    • 330 Posts
                    Thanks antspace never having used wordpress I didn’t have a clue how they did it.

                    Looks like there are currently no offical docs on the pingomatic site on how to accomplish this unless you know of any, but loads of code snippets around from other peoples sites.

                    Looks to me like all we need to do is run a very similar script that pings their server which in turn pings google, which if all you want to do is notify google seems a long way around doing, but it does have the advantage of the fact that it pings loads of other services too.

                    Anyway I’m away this week working, will have laptop with me so if I get a chance I’ll look at switching over to ping-o-matic.

                    I will also add that I tried the code above on my site and posted an update and within an hour the sitmap in webmaster tools showed up as having been updated that day, so seems to work for google.
                      • 1841
                      • 141 Posts
                      Yes the sitemap update should work, however there is a difference between Google updating the xml sitemap and crawling the site / new pages. I would suggest trying to Ping the Pingomatic, I did try to create something myself that interfaced with the pingomatic site (essentially you *should* just need to add the new page to the pingomatic URL:

                      http://pingomatic.com/ping/?title=[*sitename*]&blogurl=[*siteurl*]&rssurl=[*rssurl*](optional


                      Never got it to work, didn’t have much time and my knowledge of Modx at the time was limited...