Web Hosting
  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.

Tags:
  1. nikos_pamp

    New Member

    Joined:
    Apr 24, 2017
    Messages:
    1
    Likes Received:
    0
    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.

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

    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);

     
    #1

Share This Page

Web Hosting