Wordpress - Pagination for pages

2019-09-17 06:04发布

I have a page with the most rated posts.

I use WP-PostRatings and I use this code:

query_posts( array( 'meta_key' => 'ratings_average', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );

Is there a way to create pagination for pages?

I found something here Wordpress pagination with static pages , but it shows me in all pages, the newest posts, order by date (as in homepage)

Thank you!

1条回答
淡お忘
2楼-- · 2019-09-17 06:52

To get pagination to work with query_posts() you need to add the $paged variable to your query:

$posts_per_page = 10;
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query = array( 
    'meta_key' => 'ratings_average', 
    'orderby' => 'meta_value_num', 
    'order' => 'DESC',
    'posts_per_page' => $posts_per_page,
    'paged' => $paged
);
query_posts( $query );
查看更多
登录 后发表回答