fanbaba
www.fanyubaba.cn
Linux经验总结 / php手动修改文章排序,Typecho文章如何按修改时间排序

access_time
brush 200个字
whatshot 364 ℃
百度收录:百度已收录

Typecho文章默认是按创建时间排序的,如果只是自己访问,将文章改为按更改时间排序管理起来更方便。

1.将前台文章列表改为按修改时间排序

修改var/Widget/Archive.php1399行,将$select->order('table.contents.created', Typecho_Db::SORT_DESC)中的created改为:

modified

2.将后台的文章管理列表改为按修改时间排序

修改var/Widget/Contents/Post/Admin.php176行,将$select->order('table.contents.created', Typecho_Db::SORT_DESC)中的created改为:

modified

3.将后台文章列表中文章的时间由创建时间改为修改时间

修改admin/manage-posts.php149<?php $posts->dateWord(); ?>改为:

<?php $modifyDate = new Typecho_Date($posts->modified); ?>
<?php echo $modifyDate->word(); ?>

4.保存文章后每次都回到列表页的第一页

修改var/Widget/Contents/Post/Edit.php761行:

$this->response->redirect(Typecho_Common::url('manage-posts.php?' . $pageQuery, $this->options->adminUrl));

改为:

$this->response->redirect(Typecho_Common::url('manage-posts.php?page=1', $this->options->adminUrl));

默认主题修改以上4处就可以了,如果使用的其他主题,还要看具体的主题代码,例如handsome主题还要修改模板自带的index.php,将created改为modified。

修改前:

$endSelect = $restPostSelect->order('table.contents.created', Typecho_Db::SORT_DESC);
$rest_posts = $db->fetchAll($restPostSelect->order('table.contents.created', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize));

修改后:

$endSelect = $restPostSelect->order('table.contents.modified', Typecho_Db::SORT_DESC);
$rest_posts = $db->fetchAll($restPostSelect->order('table.contents.modified', Typecho_Db::SORT_DESC)->page($this->_currentPage, $this->parameter->pageSize));

#如无特别声明,该文章均为 fanbaba 原创,转载请遵循 署名-非商业性使用 4.0 国际(CC BY-NC 4.0) 协议,即转载请注明文章来源。
#最后编辑时间为: 2021 年 11 月 23 日


create 添加新评论


account_circle
email
language
textsms





关于小破站

主题名称:樊钰的小破站 | 版本:X2.3.211003

主题开发:Fanyu | Licheng

Designed by Fanyu Power by Typecho

Copyright © 2015-2022 by Fanyu All rights reserved!

加我的QQ
加我的微博
加我的支付宝
加我的微信