这个功用由于本身倏忽有须要,然后去论坛搜了下发明也有人问过,帖子里有人引荐了个插件能够完成,不过我倏忽想到个模板函数,就是自定义文章上下篇链接的,彷佛就能够直接完成,不须要插件。
函数以下:
/*** 显现下一篇** @access public* @param string $default 假如没有下一篇,显现的默许笔墨* @return void*/function theNext($widget, $default = NULL){$db = Typecho_Db::get();$sql = $db->select()->from('table.contents')->where('table.contents.created > ?', $widget->created)->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', $widget->type)->where('table.contents.password IS NULL')->order('table.contents.created', Typecho_Db::SORT_ASC)->limit(1);$content = $db->fetchRow($sql);if ($content) {$content = $widget->filter($content);$link = '<a href="' . $content['permalink'] . '" title="' . $content['title'] . '">下一篇</a>';echo $link;} else {echo $default;}}/*** 显现上一篇** @access public* @param string $default 假如没有下一篇,显现的默许笔墨* @return void*/function thePrev($widget, $default = NULL){$db = Typecho_Db::get();$sql = $db->select()->from('table.contents')->where('table.contents.created < ?', $widget->created)->where('table.contents.status = ?', 'publish')->where('table.contents.type = ?', $widget->type)->where('table.contents.password IS NULL')->order('table.contents.created', Typecho_Db::SORT_DESC)->limit(1);$content = $db->fetchRow($sql);if ($content) {$content = $widget->filter($content);$link = '<a href="' . $content['permalink'] . '" title="' . $content['title'] . '">上一篇</a>';echo $link;} else {echo $default;}}挪用代码<?php thePrev($this); ?>和<?php theNext($this); ?>。
能够看出内里用的是数据库语句,那末完成[Typecho无插件完成同分类文章上一篇下一篇],岂不是插进去个where语句就好了,对,就是这么简朴。
首先在函数里开头部份到场以下代码,猎取当前文章的分类mid
@$mid=intval($widget->categories[0]['mid']);然后在数据库语句中适宜位置插进去一个where语句
->where('table.relationships.mid = ?', $mid)好了,这就功德圆满了,希望能帮获得列位。

评论列表