文章上一篇与下一篇调用代码:
<?php $this->thePrev(); ?> <?php $this->theNext(); ?>
或者
<?php $this->thePrev('上一篇 : %s', '没有上一篇'); ?>
<?php $this->theNext('下一篇 : %s', '没有下一篇'); ?>
这样的会输出同时文章的标题和链接,不是很利于加样式。
不过1.0版的typecho,已经支持更灵活的上下文输出:
$this->thePrev($format = '%s', $default = NULL, $custom = array(
'title' => '',
'tagClass' => ''
));
$custom 数组部分即为自定义内容,目前支持给上下文链接添加自定义的 CSS 类名、及输出文字,文字部分支持 html 代码:
$this->thePrev('%s', NULL, array('title' => '<span>上一篇</span>', 'tagClass' => 'prev-content'));
上面的代码会输出:
<a class="prev-content" href="{permalink}" title="{title}"><span>上一篇</span></a>
老版本(亲测:其实1.0版这么用也是可以的)
/**
* 显示下一篇
*
* @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); ?>
版权属于:泽泽社长
本文链接:https://blog.zezeshe.com/archives/te-for-athe-next-link.html
本站未注明转载的文章均为原创,并采用
CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!
出一篇折腾上一页和下一页的页码教程,这篇是上一篇和下一篇。谢谢谢!
加我QQ吧,具体描述小你想要做的事情,QQ在关于页面内,左侧菜单About
我是小白,按你所说折腾上一页和下一页修改出错了,<?php $this->pageLink(\'Previous\',\'left nav prev\');?>
<?php $this->thePrev(\'%s\', NULL, array( \'tagClass\' => \'left nav prev\'));?>这样试试
我是小白,按你所说折腾上一页和下一页修改出错了,<?php $this->pageLink(\'Previous\',\'left nav prev\');?>出错,但left nav prev改为prev就行,但我的样式就变了,求解!