• Resolved ronnyrook

    (@ronnyrook)


    Hello WordPress Users,

    I’m stuck with a problem building my wordpress website and I can’t figure out what to do about it.

    Currently I’m showing 2 posts form the category ‘News’ at the page ‘News’. At the bottom of this page I want a Prev/Next button that shows the next or previous 2 posts from the same category.

    So I was searching how I coud do that.
    So I found this code:

    previous_posts_link('Newer Entries »')
    next_posts_link('« Older Entries');

    This displays a link like I was expecting.
    But both links are not working (page reload, but same entry’s shown).

    I also found this in this codex:
    posts_nav_link('∞','Go Forward In Time','Go Back in Time');

    Also at ‘Setting’ > ‘Reading’ I had set max posts to 2.

    I don’t know how I can handle this.
    Is there a way to show the next 2 (or ‘X’) posts from the same categorie when a button ‘Next’ or ‘Prev’ is pressed?

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter ronnyrook

    (@ronnyrook)

    Fixed this using the Pagination 🙂
    Code:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args_news= array(
            'cat' => 1,
            'posts_per_page' => 2,
            'orderby' => 'post_date',
            'order' => 'DESC',
            'paged' => $paged,
            'numberposts' => -1
        );
    
        $news_query = new WP_Query($args_news);
    
        if ( $news_query->have_posts() ) :
            while ( $news_query->have_posts() ) : $news_query->the_post(); 
    
                    the_title();
                    the_content();
    
            endwhile;
        endif;
          previous_posts_link('ouder', $news_query->max_num_pages);
          next_posts_link('nieuwer', $news_query->max_num_pages);

Viewing 1 replies (of 1 total)
  • The topic ‘Next/Prev posts on same page’ is closed to new replies.