This commit is contained in:
haoouba 2021-03-07 12:25:45 +08:00
parent 93d791caaa
commit ae58914638
4 changed files with 55 additions and 17 deletions

View File

@ -70,11 +70,13 @@ function themeInit($self)
};
}
/* 增加自定义sitemap功能 */
/* 增加自定义SiteMap功能 */
if (Helper::options()->JSiteMap && Helper::options()->JSiteMap !== 'off') {
if ($self->request->getRequestUri() == "/sitemap.xml" || $self->request->getRequestUri() == "/index.php/sitemap.xml") {
$self->setThemeFile("library/sitemap.php");
$self->response->setStatus(200);
}
}
}
/* 增加自定义字段 */

View File

@ -3,7 +3,7 @@
/* 获取主题当前版本号 */
function _getVersion()
{
return "5.5.9";
return "5.6.0";
};
/* 判断是否是手机 */

View File

@ -851,6 +851,34 @@ function themeConfig($form)
$JPasteUpload->setAttribute('class', 'joe_content joe_other');
$form->addInput($JPasteUpload->multiMode());
$JSiteMap = new Typecho_Widget_Helper_Form_Element_Select(
'JSiteMap',
array(
'off' => '关闭(默认)',
'100' => '显示最新 100 条链接',
'200' => '显示最新 200 条链接',
'300' => '显示最新 300 条链接',
'400' => '显示最新 400 条链接',
'500' => '显示最新 500 条链接',
'600' => '显示最新 600 条链接',
'700' => '显示最新 700 条链接',
'800' => '显示最新 800 条链接',
'900' => '显示最新 900 条链接',
'1000' => '显示最新 1000 条链接',
),
'off',
'是否开启主题自带SiteMap功能',
'介绍开启后博客将享有SiteMap功能 <br />
其他:链接为博客最新实时链接 <br />
好处:无需手动生成,无需频繁提交,提交一次即可 <br />
开启后SiteMap访问地址<br />
http(s)://域名/sitemap.xml (开启了伪静态)<br />
http(s)://域名/index.php/sitemap.xml (未开启伪静态)
'
);
$JSiteMap->setAttribute('class', 'joe_content joe_other');
$form->addInput($JSiteMap->multiMode());
$JBaiduToken = new Typecho_Widget_Helper_Form_Element_Text(
'JBaiduToken',
NULL,

View File

@ -1,16 +1,24 @@
<?php
$db = Typecho_Db::get();
$options = Typecho_Widget::widget('Widget_Options');
$pages = $db->fetchAll($db->select()->from('table.contents')
$limit = Helper::options()->JSiteMap;
$pages = $db->fetchAll(
$db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $options->gmtTime)
->where('table.contents.type = ?', 'page')
->order('table.contents.created', Typecho_Db::SORT_DESC));
$articles = $db->fetchAll($db->select()->from('table.contents')
->limit($limit)
->order('table.contents.created', Typecho_Db::SORT_DESC)
);
$articles = $db->fetchAll(
$db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $options->gmtTime)
->where('table.contents.type = ?', 'post')
->order('table.contents.created', Typecho_Db::SORT_DESC));
->limit($limit)
->order('table.contents.created', Typecho_Db::SORT_DESC)
);
header("Content-Type: application/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
@ -22,7 +30,7 @@ foreach ($pages as $page) {
echo "\t<url>\n";
echo "\t\t<loc>" . $page['permalink'] . "</loc>\n";
echo "\t\t<lastmod>" . date('Y-m-d\TH:i:s\Z', $page['modified']) . "</lastmod>\n";
echo "\t\t<changefreq>always</changefreq>\n";
echo "\t\t<changefreq>monthly</changefreq>\n";
echo "\t\t<priority>0.8</priority>\n";
echo "\t</url>\n";
}
@ -45,7 +53,7 @@ foreach ($articles as $article) {
echo "\t<url>\n";
echo "\t\t<loc>" . $article['permalink'] . "</loc>\n";
echo "\t\t<lastmod>" . date('Y-m-d\TH:i:s\Z', $article['modified']) . "</lastmod>\n";
echo "\t\t<changefreq>always</changefreq>\n";
echo "\t\t<changefreq>monthly</changefreq>\n";
echo "\t\t<priority>0.5</priority>\n";
echo "\t</url>\n";
}