【发布时间】:2018-01-17 19:16:10
【问题描述】:
有很多关于分页的问题......我已经把它们倾倒了,并整理了以下代码(见下文)。问题:某些类别页面没有显示任何结果(只有 3 个帖子的类别)。其他的没有显示该类别中的所有帖子(一个类别有 80 个帖子,但只显示 60 个)...
下面是我的代码...
在我的 category.php 页面上...
<?php
$currCat = get_category(get_query_var('cat'));
$cat_name = $currCat->name;
$cat_id = get_cat_ID( $cat_name ); // Get cat ID
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'meta_key' => 'ratings_average', // WP-Rating Plugin Rating Value
'orderby' => 'meta_value_num',
'order' => 'DESC',
'cat' => $cat_id,
'posts_per_page' => 10,
'paged' => $paged,
);
$wp_query = new WP_Query( $args );
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
get_template_part( 'entry' );
endwhile;
//Pagination
post_pagination();
else:
?>Sorry, no results at this time.<?php
endif;
?>
在我的functions.php页面上...
if ( ! function_exists( 'post_pagination' ) ) :
function post_pagination() {
global $wp_query;
$pager = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $pager, '%#%', esc_url( get_pagenum_link( $pager ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
}
endif;
【问题讨论】:
标签: wordpress pagination