在主题的文件 function.php 中加入以下代码:
/*** 显示上一篇*/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;}}/*** 显示下一篇*/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;}}
在默认让题上找到post.php 里的!--上一篇---下一篇-- 在复制到新主题里 post.php 插到合适位置
<li>上一篇: <?php $this->thePrev('%s','没有了'); ?></li> <li>下一篇: <?php $this->theNext('%s','没有了'); ?></li>