<?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:mobile=\"http://www.baidu.com/schemas/sitemap-mobile/1/\">\n";
// 查询门户文章数据
$querys = DB::query("SELECT aid FROM ".DB::table('portal_article_title')." ORDER BY aid DESC");
while($articleData = DB::fetch($querys)) {
$aid = $articleData['aid'];
$turl = $web_root . "article-$aid-1.html"; // 根据您提供的规则生成文章 URL
$link = $turl;
$t = time();
$riqi = date("Y-m-d", $t); // 获取当前日期
$priority = rand(9, 10) / 10; // 随机生成优先级
$sitemap .= "<url>\n";
$sitemap .= "<loc>$link</loc>\n"; // 页面 URL
$sitemap .= "<mobile:mobile type=\"pc,mobile\"/>\n"; // 百度自适应页面提交
$sitemap .= "<priority>$priority</priority>\n"; // 优先级
$sitemap .= "<lastmod>$riqi</lastmod>\n"; // 最后修改时间
$sitemap .= "<changefreq>daily</changefreq>\n"; // 更新频率
$sitemap .= "</url>\n";
}
$sitemap .= "</urlset>\n";
// 写入文件
$fp = fopen(DISCUZ_ROOT . '/' . $filename, 'w');
fwrite($fp, $sitemap);
fclose($fp);
?>