2017-04-24 77 views
0

因此,我修改了single-news.php文件以获取上一个/下一个按钮来浏览新闻,但该代码使用了帖子ID,例如im在属于类别1的post1中,我按下“下一个”它不一定会在同一类别中进入下一篇文章。Wordpress获取上一个/下一个按钮,使用文章中的类别

<?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> 

关于如何修改此代码的任何想法?我已经看到这已被问了很多次,但我无法实现这些帖子的想法。

我已经试过了,但它doenst显示任何东西:

$next = next_post_link($format, $link, $in_same_term = true, $excluded_terms = '', $taxonomy = 'category'); 

也为我使用Wp的新闻消息和滚动部件

编辑: 当我使用这个我有结果为相同现在

$next = get_next_post_link('&laquo; %link', '%title', FALSE); 

但是当我这样使用它是不显示任何东西:

$next = get_next_post_link('&laquo; %link', '%title', TRUE); 

回答

0
<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> 

所以这是解决方案,这是问题:我不得不改变类别的永久链接,在我的一次“新闻类”,然后执行该进next_post_link,因为如果我只是在分类学真而不指定它在错误的地方查找的分类类别。

相关问题