我有一个有分页的类别循环。第一页永远是对的。一旦我通过第一页,它就会将类别混合在一起。此外,页数总是错误的。
<?php
global $paged;
$cat = get_the_category();
$catSlug = $cat[1]->slug;
$query = new WP_Query(array('category_name' => $catSlug,'posts_per_page' => 20,'paged' => $paged));
?>
<?php
while ( $query->have_posts() ) :
$query->the_post();
?>
<li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'starkers' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<?php
global $wp_query;
$catSlug = $cat[0]->slug;
$total_pages = $wp_query->max_num_pages;
if ($total_pages > 1){
$current_page = max(1, get_query_var('paged'));
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => '?paged=%#%',
'current' => $current_page,
'total' => $total_pages,
'add_args' => array('category_name' => $catSlug)
));
}
?>