这可能不是最好的解决方案,但确实有效。需要在函数中添加以下代码。php。
add_filter(\'query_vars\', \'parameter_queryvars\' ); // Let WP accept the query argument we will use
function parameter_queryvars( $qvars )
{
$qvars[] = \'posts_per_page\';
return $qvars;
}
add_action( \'pre_get_posts\', \'change_post_per_page\' ); // Filter posts based on passed query variable if set
function change_post_per_page( $query ) {
global $wp_query;
if ( !empty($wp_query->query[\'posts_per_page\']) && is_numeric($wp_query->query[\'posts_per_page\'])) {
$query->set( \'posts_per_page\', $wp_query->query[\'posts_per_page\'] );
}
}
要打印分页,(可能需要根据您的场景进行更改)
<div class="paging-per-post">
<a href="http://<?php echo $_SERVER["HTTP_HOST"] . array_shift(explode(\'?\',$_SERVER["REQUEST_URI"])) ?>?posts_per_page=15">15</a>
<a href="http://<?php echo $_SERVER["HTTP_HOST"] . array_shift(explode(\'?\',$_SERVER["REQUEST_URI"])) ?>?posts_per_page=30">30</a>
<a href="http://<?php echo $_SERVER["HTTP_HOST"] . array_shift(explode(\'?\',$_SERVER["REQUEST_URI"])) ?>?posts_per_page=50">50</a>
</div>