Wordpress php仅显示同一类别中的下一篇文章链接 [英] Wordpress php Only show next post link in same category

查看:27
本文介绍了Wordpress php仅显示同一类别中的下一篇文章链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 WP 的下一篇文章链接功能来显示指向同一类别中的下一篇文章"的下一个和上一个导航链接,这一切都很好……我遇到的问题是当我处于最后一个"时一个类别的帖子,无论如何都会出现NEXT"链接并做我不想做的事情:链接到不同类别的第一个帖子.与类别的第一篇文章相同,当浏览类别的第一篇文章时,PREVIOUS"链接出现链接到另一个不同类别的上一篇文章......我希望在第一篇也是最后一篇文章中,这个链接是未显示.

 

</div><!-- #nav-above -->

解决方案

您需要使用 get_previous_post_link 和 get_next_post_link 函数测试是否有下一篇或上一篇文章.例如:

<?php endif;?></div><!-- #nav-above -->

Im using the next post link function of WP to show next and previous navigation links to the "next post in same category" all good with this...the issue i have is that when I'm in the "last" post of a category, the "NEXT" link appears anyway and doing what i dont want: linking to a different category 1st post. the same with the 1st post of a category, when browsing the first post of a category the "PREVIOUS" link appears linking to previous post of a another different category... I would like that in the 1st and last post, this links aren't shown.

   <div id="nav-above" class="navigation">
                        <div class="nav-previous"><?php previous_post_linknext_post_link( '%link', '<span class="meta-nav">' .     
        _x( '&#9668; Previous', 'Previous post link','category' ,TRUE ) . '</span>' ); ?></div>
                        <div class="nav-next"><?php next_post_link( '%link', '<span class="meta-nav">' . _x( 'Next &#9658; ', 'Next post link', 'category',TRUE ) . '</span>' ); ?> </div>
                    </div><!-- #nav-above -->

解决方案

You need to test whether there is a next or previous post by using the get_previous_post_link and get_next_post_link functions. For example:

<div id="nav-above" class="navigation">

    <?php $prev = get_previous_post_link( '%link', '<span class="meta-nav">' .     
    _x( '&#9668; Previous', 'Previous post link','category' ,TRUE ) . '</span>' ); ?>
    <?php if ($prev) : ?>
    <div class="nav-previous"><?php echo $prev ?></div>
    <? endif; ?>

    <?php $next = get_next_post_link( '%link', '<span class="meta-nav">' . _x( 'Next &#9658; ', 'Next post link', 'category',TRUE ) . '</span>' ); ?>
    <?php if ($next) : ?>
     <div class="nav-next"><?php echo $next ?> </div>
    <?php endif; ?>

</div><!-- #nav-above -->

这篇关于Wordpress php仅显示同一类别中的下一篇文章链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆