简体   繁体   中英

Problem with pagination in Wordpress custom template

I created a new template in Wordpress to show the latest articles. After, I will sort them in other ways. My problem is I can not use the pagination correctly.

The next page and previous page are working ok, but the posts are not changed. The first three are the only that are shown.

Can you give me a clue about this ?

<?php
/*
Template Name: Latest Prizes
*/
get_header(); 


// The Query
query_posts( 'posts_per_page=3' );

// The Loop
while ( have_posts() ) : the_post();
    echo '<li>';
    the_title();
    echo '</li>';
endwhile;

posts_nav_link(' &#183; ', 'previous page', 'next page');


// Reset Query
wp_reset_query();


get_footer(); ?>

From the Wordpress Codex on query_posts() :

...

For example, on the homepage, you would normally see the latest 10 posts. If you want to show only 5 posts ( and don't care about pagination ), you can use query_posts() like so:

query_posts( 'posts_per_page=5' );

Change your query_posts() to this:

query_posts(array('posts_per_page' => 3, 'paged' => get_query_var('page')));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM