Quick Tip: Dynamic Google Sitemaps
Today’s quick affiliate marketing tip is how to dynamically build an XML sitemap for use with Google’s Sitemap tool. Such a sitemap gives the Google spider a quick listing of all the web pages on your site as well as the date they were last updated. Thus it helps get more pages spidered and makes sure the pages in its index are the freshest possible.
To use this script, create a file called sitemap.php in your main web directory, insert your site’s URL into the code and submit it to Google. Please let me know if you have any questions or comments about the script by leaving a comment.
<?= '<?xml version="1.0" encoding="UTF-8"?>' . "n"; ?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<?
$baseurl = "http://www.URL.com/";
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
if ((substr($file, -5) == ".html") ||
(substr($file, -4) == ".php")) { ?>
<url>
<loc><?= $baseurl . ((substr($file, 0, 6) !=
"index.") ? $file : "") ?></loc>
<lastmod><?= date ("Y-m-dTH:i:s",
filemtime("" . $file)) ?>-05:00</lastmod>
<changefreq>monthly</changefreq>
</url>
<? } } ?>
</urlset>