Typecho 实现文章上一篇下一篇功能的教程如下:

没用的小知识 · 19 天前

在主题的文件 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> 

 

  • 上一篇: 只写标题,不写内容
  • 下一篇: Typecho的ckEditor编辑器
  • Theme Jasmine