typecho内容页面如何获得同级分类下的上一篇和下一篇文章标题

用分类功能区别了作品与博客,在内容页面如何获得同级分类下的上一篇和下一篇文章标题?

<div class="prev-next">
  <div class="prev-button"><?php $this->thePrev('%s'); ?></div>
  <div class="next-button"><?php $this->theNext('%s'); ?></div>
</div>
阅读 4.9k
4 个回答

以下代码通过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 '';
    }
}

得修改系统核心代码,

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进