typecho内容页面如何获得同级分类下的上一篇和下一篇文章标题
本文介绍了typecho内容页面如何获得同级分类下的上一篇和下一篇文章标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
用分类功能区别了作品与博客,在内容页面如何获得同级分类下的上一篇和下一篇文章标题?
<div class="prev-next">
<div class="prev-button"><?php $this->thePrev('%s'); ?></div>
<div class="next-button"><?php $this->theNext('%s'); ?></div>
</div>
解决方案
以下代码通过prev_post($this)
进行调用
function prev_post($archive)
{
$db = Typecho_Db::get();
$content = $db->fetchRow($db->select()
->from('table.contents')
->where('table.contents.created < ?', $archive->created)
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', $archive->type)
->where('table.contents.password IS NULL')
->order('table.contents.created', Typecho_Db::SORT_DESC)
->limit(1));
if ($content)
{
$content = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($content);
echo '<div class="nav-previous"><a href="' . $content['permalink'] . '" rel="prev"><span class="meta-nav">上一篇: </span> <span class="post-title">' . $content['title'] . '</span></a></div>';
}
else
{
echo '';
}
}
function next_post($archive)
{
$db = Typecho_Db::get();
$content = $db->fetchRow($db->select()
->from('table.contents')
->where('table.contents.created > ? AND table.contents.created < ?', $archive->created, Helper::options()->gmtTime)
->where('table.contents.status = ?', 'publish')
->where('table.contents.type = ?', $archive->type)
->where('table.contents.password IS NULL')
->order('table.contents.created', Typecho_Db::SORT_ASC)
->limit(1));
if ($content)
{
$content = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($content);
echo '<div class="nav-next"><a href="' . $content['permalink'] . '" rel="next"><span class="meta-nav">下一篇: </span> <span class="post-title">' . $content['title'] . '</span></a></div>';
}
else
{
echo '';
}
}
这篇关于typecho内容页面如何获得同级分类下的上一篇和下一篇文章标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文