用分类功能区别了作品与博客,在内容页面如何获得同级分类下的上一篇和下一篇文章标题?
<div class="prev-next">
<div class="prev-button"><?php $this->thePrev('%s'); ?></div>
<div class="next-button"><?php $this->theNext('%s'); ?></div>
</div>
这里有更简洁的方法
http://t.160.me/33.html
得修改系统核心代码,
以下代码通过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 '';
}
}