You are here:  » Google Sitemap script


Google Sitemap script

Submitted by arthuc01 on Sat, 2006-02-11 19:07 in

Quick google sitemap code for PT

<?php
  require("includes/common.php");
  require("includes/database.php");
  require("includes/tapestry.php");
  print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  print "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">\n";
    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` LIMIT 49999";
  $date=date("Y-m-d");
    if ($numRows = database_querySelect($sql,$rows))
    {
      $htaccessExists = file_exists(".htaccess");
      foreach($rows as $product)
      {
        if ($htaccessExists)
        {
          $productHREF = $config_baseHREF."product/".str_replace(" ","-",$product["name"]).".html";
        }
        else
        {
          $productHREF = $config_baseHREF."product.php?q=".urlencode($product["name"]);
        }
        print "<url>\n<loc>".$productHREF."</loc>\n";
     print "<lastmod>".$date."</lastmod>\n";
     print "<changefreq>monthly</changefreq>\n";
     print "<priority>0.8</priority>\n";
print "</url>\n";
      }
        print "</urlset>\n";
      }
?>

It only lists the first 49999 products (google sets a maximium of 50000 URLS in one sitemap). If you want more then it should be possible to tweak the code to do multiple pages giving it a dynamic url.

Have fun

An example of output can be seen at (10 products)
http://now3k.co.uk/sitemap_example.php

Submitted by support on Sat, 2006-02-11 19:15

Nice! Thanks for the contribution.

I've got sitemap support on the list to include in a later version...It should be reasonably straight forward to create a dynamic sitemap index per merchant; and have individual "virtual":

/merchant/merchant-name/sitemap.xml

..etc. documents generated on the fly...

Submitted by arthuc01 on Sat, 2006-02-11 19:51

no problem, feel free to include the script as a preliminary version in the distro if you want