Typecho自定义上下篇链接

typecho教程 2020-08-25

  在 functions.php 中编写

  

新版本

  新版本里,已经支持更灵活的上下文输出:

  $this->thePrev($format = ‘%s’, $default = NULL, $custom = array(

  ’title’ => ”,

  ’tagClass’ => ”

  ));

  $custom 数组部分即为自定义内容,目前支持给上下链接添加自定义的 CSS 类名、及输出文字,文字部分支持 html 代码:

  $this->thePrev(‘%s’, NULL, array(‘title’ => ‘上一篇‘, ‘tagClass’ => ‘prev-content’));

  上面的代码会输出:

  上一篇

  

老版本

  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 = ‘下一篇’;

  echo $link;

  } else {

  echo $default;

  }

  }

  function thePrev($widget, $default = NULL)

  {

  $db = Typecho_Db::get();

  $sql = $db->select()->from(‘table.contents’)

  ->where(‘table.contents.created 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 = ‘上一篇’;

  echo $link;

  } else {

  echo $default;

  }

  }

  调用代码:

  

评论 (0)
    Top