PHPCMS V9 全站Sitemap生成[服务器端版]
需求:
通过服务器的定时任务自动更新网站全站的所有文章,并生成sitemap
以下代码为sitemap crontab for phpcms v9,以下代码保存到phpcms 根目录下,配置cronTab定时生成即可
[php]
<?php
/**
* sitemap.php PHPCMS V9 sitemap入口
*
* @copyright (C) 2005-2011 www.4wei.cn
* @license http://www.4wei.cn
* @lastmodify 2011-12-06
*/
if(PHP_SAPI != ‘cli’)
{
header(‘location: sitemap.xml’);
exit;
}
define(‘SITEMAP_SIZE’, 10000); //sitemap中最大输出数量
define(‘MODEL_SIZE’, 3000); //每个模型中最大输出数量
$model_arr = array(12=>’资讯’, 13=>’评测’, 14=>’教程’); //定义需要生成sitemap的模型
define(‘PHPCMS_PATH’, dirname(__FILE__).DIRECTORY_SEPARATOR);
include PHPCMS_PATH.’/phpcms/base.php’;
$param = pc_base::load_sys_class(‘param’);
$model_arr = empty($model_arr) ? getcache(‘model’,’commons’) : $model_arr;
$map = array();
foreach ($model_arr as $modelid => $model)
{
$tablename = $model[‘tablename’];
$db = pc_base::load_model(‘content_model’);
$db->set_model($modelid);
if($db->count() && count($map) < SITEMAP_SIZE)
{
$order = ‘id desc’;
$arc = $db->select(array(‘status’=>99), ‘url,updatetime’, MODEL_SIZE, $order);
$map = array_merge($map, $arc);
}
}
/* 遍历生成 */
$html = ‘<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">’;
foreach ($map as $row)
{
if(empty($row) || empty($row[‘url’])) continue;
$date = date("Y-m-d", $row[‘updatetime’]);
$url = str_replace(array(‘&’, ‘\”, ‘"’, ‘>’, ‘<‘), array(‘&’, ‘'’, ‘"’, ‘>’, ‘<’), $row[‘url’]);
$html .= "
<url>
<loc>{$url}</loc>
<lastmod>{$date}</lastmod>
<changefreq>daily</changefreq>
<priority>0.8</priority>
</url>";
}
$html .= ‘</urlset>’;
file_put_contents(‘./sitemap.xml’, $html);
?>
[/php]
v9的iis 如何设置呢?
请问下:配置cronTab定时生成这一步要怎么操作呢?
谢谢了。
可以不可以啊?
This XML file does not appear to have any style information associated with it. The document tree is shown below. 怎么解决哦?
试了一下,不行啊,提示一个错误如下:This XML file does not appear to have any style information associated with it. The document tree is shown below.
你写得实在是太好了。我唯一能做的,就只有把这个顶上了。