王尘宇王尘宇

研究百度干SEO做推广变成一个被互联网搞的人

Typecho自定义上下篇链接

Typecho自定义上下篇链接


在 functions.php 中编写
<div style="font-size: 30px;">新版本</div>

新版本里,已支撑更天真的上下文输出:

$this->thePrev($format = '%s', $default = NULL, $custom = array(    'title' => '',    'tagClass' => ''));

$custom 数组部份即为自定义内容现在支撑给上下文链接增加自定义的 CSS 类名、及输出笔墨,笔墨部份支撑 html 代码:

$this->thePrev('%s', NULL, array('title' => '<span>上一篇</span>', 'tagClass' => 'prev-content'));

上面的代码会输出:

<span>上一篇</span>

<div style="font-size: 30px;">老版本</div>

/*** 显现下一篇** @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'] . '">下一篇';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'] . '">上一篇';echo $link;} else {echo $default;}}

挪用代码:

<?php thePrev($this); ?&gt; 和 &lt;?php theNext($this); ?>


相关文章

评论列表

发表评论:
验证码

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。