Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wordpress get the previous/next buttons to work using category inside article

Discussion in 'Troubleshooting & How-To's' started by nikos_pamp, Apr 24, 2017.

  1. nikos_pamp

    New Member

    Apr 24, 2017
    Likes Received:
    So I modified the single-news.php file in order to get a previous/next button to navigate the news but that code uses the post id and for example im at post1 which belongs to category1, what I press "next" it doesnt go the next post in the same category necessarily.

    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 class="col-xs-6 text-right">
    <?php echo wp_kses_post( $next ) ?>

    Any idea on how I should modify this code? I've seen that this has been asked many times but I couldnt implement the ideas from these posts.

    I have tried that but it doenst show anything:

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

    Also for the news I use the Wp news and Scrolling widgets

    Edit: when I use this I have the same result as now

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

    but when I use it like this is doesn't show anything:

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


Share This Page

Monarch Social Sharing Plugin