引入类库
require_once 'library/Sitemap.php';
初始化
$sitemap = new SitemapGenerator('http://www.xxx.com/', $base_dir);
// will create also compressed (gzipped) sitemap
$sitemap->createGZipFile = true;
// determine how many urls should be put into one file
$sitemap->maxURLsPerSitemap = 10000;
// sitemap file name
$sitemap->sitemapFileName = 'sitemap.xml';
// sitemap index file name
$sitemap->sitemapIndexFileName = 'sitemap-index.xml';
// robots file name
$sitemap->robotsFileName = 'robots.txt';
添加网站地图URL 第一个参数是访问地址 第二个参数是 修改日期 第三个上述是修改频率 第四个参数是URL权重
$sitemap->addUrl("http://www.xxx.la/com/{$cate['id']}.html", date('c'), 'daily', '0.6');
生成地图
try {
// create sitemap
$sitemap->createSitemap();
// write sitemap as file
$sitemap->writeSitemap();
// update robots.txt file
$sitemap->updateRobots();
// submit sitemaps to search engines
// $result = $sitemap->submitSitemap('yahooAppId');
// shows each search engine submitting status
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}