sitemap.txt 得到文章网址列表
Typecho插件
本项目Github地址:https://github.com/xiaoaozhi3/typecho-sitemap-txt
Sitemap插件下载地址:https://github.com/bayunjiang/typecho-sitemap
下载完成解压后,可以看到以下三个文件:
因为最后生成的是txt文件,所以不需要样式表。我们将sitemap.xsl
文件删除。
下面修改两个php文件。
Plugin.php修改后:
class Sitemaptxt_Plugin implements Typecho_Plugin_Interface
{
/**
* 激活插件方法,如果激活失败,直接抛出异常
*
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function activate(){
Helper::addRoute('sitemaptxt', '/sitemap.txt', 'Sitemaptxt_Action', 'action');
}
/**
* 禁用插件方法,如果禁用失败,直接抛出异常
*
* @static
* @access public
* @return void
* @throws Typecho_Plugin_Exception
*/
public static function deactivate(){
Helper::removeRoute('sitemaptxt');
}
/**
* 获取插件配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form 配置面板
* @return void
*/
public static function config(Typecho_Widget_Helper_Form $form){}
/**
* 个人用户的配置面板
*
* @access public
* @param Typecho_Widget_Helper_Form $form
* @return void
*/
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
}
Action.php
修改后:
class Sitemaptxt_Action extends Typecho_Widget implements Widget_Interface_Do
{
public function action()
{
$db = Typecho_Db::get();
$options = Typecho_Widget::widget('Widget_Options');
$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')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $options->gmtTime)
->where('table.contents.type = ?', 'post')
->order('table.contents.created', Typecho_Db::SORT_DESC));
header("Content-Type: text/plain");
foreach($pages AS $page) {
$type = $page['type'];
$routeExists = (NULL != Typecho_Router::get($type));
$page['pathinfo'] = $routeExists ? Typecho_Router::url($type, $page) : '#';
$page['permalink'] = Typecho_Common::url($page['pathinfo'], $options->index);
echo $page['permalink']."\n";
}
foreach($articles AS $article) {
$type = $article['type'];
$article['categories'] = $db->fetchAll($db->select()->from('table.metas')
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
->where('table.relationships.cid = ?', $article['cid'])
->where('table.metas.type = ?', 'category')
->order('table.metas.order', Typecho_Db::SORT_ASC));
$article['category'] = urlencode(current(Typecho_Common::arrayFlatten($article['categories'], 'slug')));
$article['slug'] = urlencode($article['slug']);
$article['date'] = new Typecho_Date($article['created']);
$article['year'] = $article['date']->year;
$article['month'] = $article['date']->month;
$article['day'] = $article['date']->day;
$routeExists = (NULL != Typecho_Router::get($type));
$article['pathinfo'] = $routeExists ? Typecho_Router::url($type, $article) : '#';
$article['permalink'] = Typecho_Common::url($article['pathinfo'], $options->index);
echo $article['permalink']."\n";
}
}
}
全部保存,将文件夹的名称改为Sitemaptxt
,上传插件。
效果图如下:
博主大大,这个我修改后上传好,并在typecho启动它,然后好像没啥反应,它这个sitemap.txt是生成在哪
因为这个插件是根据原来的sitemap插件修改的,所以博客的目录不会生成sitemap.txt文件。你的网站的sitemap.txt地址为https://www.myyblog.cn/sitemap.txt 可以正常访问。
收到,谢谢了(!)[zface_12.png]
好久不见啊,快中秋了,提前祝你中秋快乐
同乐!
非技术的路过。