由于typecho1.2 代码写法有变,之前旧版本的排序文件替换后无法使用,本文介绍typecho1.2 手动添加自定义导航自定义排序功能。

导航主题包内附带有打包好的替换文件,可以直接上传覆盖即可,本文仅提供代码解释及有需求要手动替换的用户。

涉及修改的文件有3个

  1. /admin/write-post.php
  2. /var/Widget/Contents/Post/Edit.php
  3. /var/Widget/Archive.php

我们从第一个开始,添加后台字段设置表单

1. 修改/admin/write-post.php

在大约110行处,添加排序设置表单

<section class="typecho-post-option">
<label for="order" class="typecho-label">排序</label>
<p><input id="order" name="order" type="text" value="<?php $post->order();?>" class="w-100 text" /></p>
<p class="description">文章排序,数字越大位置越靠前,不需要则不填,默认为0。</p>
</section>

2.修改/var/Widget/Contents/Post/Edit.php

大约在267行处,添加’order’ 函数,添加表单提交函数

'order',

如图:

%title插图%num

3.修改/var/Widget/Archive.php

大约在1382行处,替换下边部分代码,调整前台自定义排序调用

/** 如果已经提前压入则直接返回 */
if ($hasPushed) {
return;
}
if (isset($this->parameter->order)) {
$order = $this->parameter->order;
}else {
$order = 'created';
}
/** 仅输出文章 */
$this->_countSql = clone $select;
$select->order('table.contents.'.$order, $this->parameter->asc ? Typecho_Db::SORT_ASC : Typecho_Db::SORT_DESC)
->page($this->_currentPage, $this->parameter->pageSize);
$this->query($select);
}

如图:%title插图%num

© 版权声明
评论 抢沙发

请登录后发表评论

    暂无评论内容