Php Wordpress使用文章中的类别获取上一个/下一个按钮

Php Wordpress使用文章中的类别获取上一个/下一个按钮,php,wordpress,Php,Wordpress,因此,我修改了single-news.php文件,以获得浏览新闻的上一个/下一个按钮,但该代码使用了post id,例如im at post1,它属于category1,我按下的“next”不一定会进入同一类别的下一篇文章 <?php if ( is_single() ): $prev = get_previous_post_link(); $prev = str_replace( '&laquo;', '<div class="wrapper">

因此,我修改了single-news.php文件,以获得浏览新闻的上一个/下一个按钮,但该代码使用了post id,例如im at post1,它属于category1,我按下的“next”不一定会进入同一类别的下一篇文章

    <?php
if ( is_single() ):
    $prev = get_previous_post_link();
    $prev = str_replace( '&laquo;', '<div class="wrapper"><span class="fa fa-angle-left"></span>', $prev );
    $prev = str_replace( '</a>', '</a></div>', $prev );
    $next = get_next_post_link();
    $next = str_replace( '&raquo;', '<span class="fa fa-angle-right"></span></div>', $next );
    $next = str_replace( '<a', '<div class="wrapper"><a', $next );
    ?>
    <div class="shapely-next-prev row">
        <div class="col-xs-6 text-left" >
            <?php echo wp_kses_post( $prev ) ?>
        </div>
        <div class="col-xs-6 text-right">
            <?php echo wp_kses_post( $next ) ?>
        </div>
    </div>
对于新闻,我也使用Wp新闻和滚动小部件

编辑: 当我使用这个时,我得到了与现在相同的结果

    $next = get_next_post_link('&laquo; %link', '%title', FALSE);
但当我像这样使用它时,它不会显示任何内容:

$next = next_post_link( $format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'category' );
    $next = get_next_post_link('&laquo; %link', '%title', TRUE);

<div class="col-xs-6 text-right">           
    <div class="wrapper">          
      <?php
        next_post_link('
        %link <span class="fa fa-angle-right"></span>',
        '%title',true,'','news-category');
      ?>          
    </div>        
</div>