需要修改此解决方案,因为分页函数位于函数中。php。
我使用的是Revire主主题(它使用的是基础框架),该主题使用的是函数中的分页函数。php
if( ! function_exists( \'reverie_pagination\' ) ) {
function reverie_pagination() {
global $wp_query;
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', get_pagenum_link($big) ),
\'current\' => max( 1, get_query_var(\'paged\') ),
\'total\' => $wp_query->max_num_pages,
\'mid_size\' => 5,
\'prev_next\' => True,
\'prev_text\' => __(\'«\'),
\'next_text\' => __(\'»\'),
\'type\' => \'list\'
) );
// Display the pagination if more than one page is found
if ( $paginate_links ) {
echo \'<div class="pagination-centered">\';
echo $paginate_links;
echo \'</div><!--// end .pagination -->\';
}
}
}
我已将此函数修改为
if( ! function_exists( \'reverie_pagination\' ) ) {
function reverie_pagination() {
global $wp_query, $another_query;
$big = 999999999; // This needs to be an unlikely integer
if ( is_front_page()) {
$myqueryis = $another_query;
$paged = ( get_query_var(\'page\') ) ? get_query_var(\'page\') : 1;
} else {
$myqueryis = $wp_query;
$paged = get_query_var(\'paged\');
}
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
\'base\' => str_replace( $big, \'%#%\', get_pagenum_link($big) ),
\'current\' => max( 1, $paged ),
\'total\' => $myqueryis->max_num_pages,
\'mid_size\' => 5,
\'prev_next\' => True,
\'prev_text\' => __(\'«\'),
\'next_text\' => __(\'»\'),
\'type\' => \'list\'
) );
// Display the pagination if more than one page is found
if ( $paginate_links ) {
echo \'<div class="pagination-centered">\';
echo $paginate_links;
echo \'</div><!--// end .pagination -->\';
}
}
}
变量$another\\U query是我的自定义WP\\U查询。此问题作者使用*query\\u posts*获得结果,但我使用*new WP\\u query*。
我在头版中使用的查询是;
$args = array(
\'post_type\' => \'post\',
\'post__not_in\' => $do_not_duplicate,
\'paged\' => $paged,
);
$another_query = new WP_Query( $args );