Discuz轻松生成sitemaps.xml网站地图
只针对论坛版块生成sitemaps.xml:●建立一个名为“cron_sitemaps.php”的文件;
●复制以下代码区的内容到“cron_sitemaps.php”中,并保存文件;
PS:注意编码,选择自己DZ对应的编码,我自己用的是UTF-8版本DZ
<?php
/*
* $ 自动生成网站地图sitemap.xml
* 1、discuz后台添加定时任务:后台–工具–计划任务–新增,名字随便,提交
* 2、然后编辑,任务脚本:cron_sitemap.php
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
$cfg_updateperi='60';//协议文件更新周期的上限,单位为分钟
$CHARSET='gbk';// 选择编码方式:utf-8 or gbk
/******************************************自动生成网站地图****************************************************/
$txtContent = '';
$sitemap="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap.="<urlset\n";
$sitemap.="xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\"> \n";
//1.文章
$queryArticle = DB::query("SELECT aid FROM ".DB::table('portal_article_title').' ORDER BY aid DESC');
while($articleaid = DB::fetch($queryArticle)){
$link = "{$_G}article-{$articleaid['aid']}-1.html";//注意静态规则
$txtContent .= $link."\n";
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>weekly</changefreq>\n";
$sitemap.="</url>\n";
}
//2.帖子
$queryThread = DB::query("SELECT tid FROM ".DB::table('forum_thread').' WHERE displayorder=0 ORDER BY tid DESC');
while($threadfid = DB::fetch($queryThread)){
$link = "{$_G}thread-{$threadfid['tid']}-1-1.html";//注意静态规则
$txtContent .= $link."\n";
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>weekly</changefreq>\n";
$sitemap.="</url>\n";
}
$sitemap .= "</urlset>\n";
//写入xml文件
$fp = fopen(DISCUZ_ROOT.'/sitemap.xml','w');
fwrite($fp,$sitemap);
fclose($fp);
//写入txt文件
$fopen = fopen(DISCUZ_ROOT.'/sitemap.txt',"w+");
fwrite($fopen,$txtContent);
fclose($fopen);
?>
●上传“cron_sitemaps.php”到source\include\cron目录;
●到discuz后台添加定时任务:后台→工具→计划任务→新增→提交;
●接下来编辑任务,任务脚本填“cron_sitemaps.php”
●首次先手动执行一次该计划任务,在站点根目录会生成名为"sitemaps.xml"的文件,这样就完成了网站地图的生成,一劳永逸,就这么简单。
楼主亲测,大家放心用! 占个坑先!!! 亲测有用:D * $ 自动生成网站地图sitemap.xml
* 1、discuz后台添加定时任务:后台–工具–计划任务–新增,名字随便,提交
* 2、然后编辑,任务脚本:cron_sitemap.php {:3_41:} 7楼了!!! 8楼了!!!!
页:
[1]