How to paginate a custom WP_query() loop - Wordpress

只谈情不闲聊 提交于 2019-12-11 06:53:49

问题


I have a blog page that calls posts with tag 'blog'. So i called a custom WP_query() object: $blog = new WP_query('tag=blog');.

The result works fine, but when i paginate the posts, the links always is shown even if doesn't exist more than 10 posts (the default limit).

How can i fix it?


回答1:


just add the following code

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

then you query will be like as following

$blog = new WP_query('tag=blog&posts_per_page=10&paged=' . $paged);



来源:https://stackoverflow.com/questions/23807474/how-to-paginate-a-custom-wp-query-loop-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!