一、新建 php 文件,命名为:
添加内容:(有三种格式)
1、纯论坛帖子
[CSS] 纯文本查看 复制代码 <?php
if(!defined('IN_DISCUZ')) {
exit('access Denied');
}
$filename='sitemap.xml';
//以下五项根据具体情况修改即可
$cfg_updateperi='60';//协议文件更新周期的上限,单位为分钟
$web_root=$_G['siteurl'];//根网址
$CHARSET='utf-8';// or gbk //选择编码方式
/***********************************************************************************************/
//网站地图sitemap.xml
$sitemap="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap.="<urlset\n";
$sitemap.="xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
$sitemap.="xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
$sitemap.="xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n";
$sitemap.="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
$querys = DB::query("SELECT a.tid FROM ".DB::table('forum_thread')." a inner join ".DB::table('forum_forum')." b on a.fid=b.fid ORDER BY a.tid DESC LIMIT 0,10000");
while($threadfid = DB::fetch($querys))
{
$turl=$web_root.'thread-'.$threadfid['tid'].'-1-1.html';//注意静态规则
$link = $turl;
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
//date("D F d Y",$t);
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>hourly</changefreq>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="</url>\n";
}
$sitemap .= "</urlset>\n";
$fp = fopen(DISCUZ_ROOT.'/'.$filename,'w');
fwrite($fp,$sitemap);
fclose($fp);
?>
cron_sitemap.zip
(990 Bytes, 下载次数: 31)
2、纯门户文章
[CSS] 纯文本查看 复制代码 <?php
if(!defined('IN_DISCUZ')) {
exit('access Denied');
}
$filename='sitemap.xml';
//以下五项根据具体情况修改即可
$cfg_updateperi='60';//协议文件更新周期的上限,单位为分钟
$web_root=$_G['siteurl'];//根网址
$CHARSET='utf-8';// or gbk //选择编码方式
/***********************************************************************************************/
//网站地图sitemap.xml
$sitemap="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap.="<urlset\n";
$sitemap.="xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
$sitemap.="xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
$sitemap.="xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n";
$sitemap.="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
$querys = DB::query("SELECT aid FROM ".DB::table('portal_article_title').' ORDER BY aid DESC');
$data = '';
while($articleaid = DB::fetch($querys))
{
$aurl =$web_root.'article-'.$articleaid['aid'].'-1.html';//注意静态规则
$link = $aurl;
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
//date("D F d Y",$t);
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>hourly</changefreq>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="</url>\n";
}
$sitemap .= "</urlset>\n";
$fp = fopen(DISCUZ_ROOT.'/'.$filename,'w');
fwrite($fp,$sitemap);
fclose($fp);
?>
cron_sitemap.zip
(966 Bytes, 下载次数: 24)
3、论坛帖子➕门户文章
[CSS] 纯文本查看 复制代码 <?php
if(!defined('IN_DISCUZ')) {
exit('access Denied');
}
$filename='sitemap.xml';
//以下五项根据具体情况修改即可
$cfg_updateperi='60';//协议文件更新周期的上限,单位为分钟
$web_root=$_G['siteurl'];//根网址
$CHARSET='utf-8';// or gbk //选择编码方式
/***********************************************************************************************/
//网站地图sitemap.xml
$sitemap="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$sitemap.="<urlset\n";
$sitemap.="xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";
$sitemap.="xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
$sitemap.="xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\n";
$sitemap.="http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">\n";
$querys = DB::query("SELECT a.tid FROM ".DB::table('forum_thread')." a inner join ".DB::table('forum_forum')." b on a.fid=b.fid ORDER BY a.tid DESC LIMIT 0,10000");
while($threadfid = DB::fetch($querys))
{
$turl=$web_root.'thread-'.$threadfid['tid'].'-1-1.html';//注意静态规则
$link = $turl;
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
//date("D F d Y",$t);
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>hourly</changefreq>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="</url>\n";
}
$querys = DB::query("SELECT aid FROM ".DB::table('portal_article_title').' ORDER BY aid DESC');
$data = '';
while($articleaid = DB::fetch($querys))
{
$aurl =$web_root.'article-'.$articleaid['aid'].'-1.html';//注意静态规则
$link = $aurl;
$t=time();
$riqi=date("Y-m-d",$t);
$priority=rand(1,10)/10;
//date("D F d Y",$t);
$sitemap.="<url>\n";
$sitemap.="<loc>$link</loc>\n";
$sitemap.="<lastmod>$riqi</lastmod>\n";
$sitemap.="<changefreq>hourly</changefreq>\n";
$sitemap.="<priority>$priority</priority>\n";
$sitemap.="</url>\n";
}
$sitemap .= "</urlset>\n";
$fp = fopen(DISCUZ_ROOT.'/'.$filename,'w');
fwrite($fp,$sitemap);
fclose($fp);
?>
cron_sitemap.zip
(991 Bytes, 下载次数: 27)
二、把 cron_sitemap.php 文件上传到 /source/include/cron 目录。
三、到后台➡工具➡计划任务➡新增,名字随便填写,点击提交。然后编辑,任务脚本:cron_sitemap.php,如下图:
Discuz! 网站免插件使用定时任务自动生成sitemap.xml文件
网站地图的访问地址:https://你的域名/sitemap.xml
|