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!
Edit:
This is how I get the posts:
$args_news= array(
'cat' => 1,
'posts_per_page' => 2,
'orderby' => 'post_date',
'order' => 'DESC'
);
query_posts( $args_news );
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
the_title();
the_content();
endwhile;
endif;
But still no idea how I can make pages of this posts.
Currenty it’s displaying the last 2 posts..
Pass
Paged
into parameter array ofquery_posts
You should set
get_query_var( 'paged' );
if you want your query to work with pagination.for more information:https://codex.wordpress.org/Pagination
You both have to use the
paged
query var for the loop, and themax_num_pages
var for the links: