Ajax software
Free javascripts
↑
Main Page
Generating Sitemaps
1.
In your
seophp/include
folder, create a new file named
sitemap.inc.php
, with this code:
<?php
// sitemap generator class
class Sitemap
{
// constructor receives the list of URLs to include in the sitemap
function Sitemap($items = array())
{
$this->_items = $items;
}
// add a new sitemap item
function addItem($url,
$lastmod = ‘’,
$changefreq = ‘’,
$priority = ‘’,
$additional_fields = array())
{
$this->_items[] = array_merge(array(‘loc’ => $url,
‘lastmod’ => $lastmod,
‘changefreq’ => $changefreq,
‘priority’ => $priority),
$additional_fields);
}
// get Google sitemap
function getGoogle()
{
ob_start();
header(‘Content-type: text/xml’);
echo ‘<?xml version=”1.0” encoding=”UTF-8”?>’;
echo ‘<urlset xmlns=”http://www.google.com/schemas/sitemap/0.84”>’;
foreach ($this->_items as $i)
{
echo ‘<url>’;
foreach ($i as $index => $_i)
{
if (!$_i) continue;
echo “<$index>” . $this->_escapeXML($_i) . “</$index>”;
}
echo ‘</url>’;
}
echo ‘</urlset>’;
return ob_get_clean();
}
// get Yahoo sitemap
function getYahoo()
{
ob_start();
204
Chapter 9: Sitemaps
c09.qxd:c09 10:43 204
Ajax software
Free javascripts
→