wordpress函数query_posts中posts_per_page的值无效的解决方法

wordpress函数query_posts中posts_per_page的值无效的解决方法

原因:当后台设置-阅读里的文章数大于post_per_page 时,其值是无效的。
方法1 :把'posts_pre_page' => 1改为 'showposts' => 1

方法2:用wp_query() 函数来代替 query_posts()

方法3:在function.php定义特殊分类显示

function custom_posts_per_page($query){
if( is_category('wordpress-themes') && $query->is_main_query() ) {
$query->set('posts_per_page', 20);
}
}
add_action('pre_get_posts', 'custom_posts_per_page');