0
我有一個有分頁的類別循環。第一頁總是正確的。一旦我翻過第一頁,就會混合在一起。另外,頁面數量總是錯誤的。爲什麼第2頁的單詞分頁制動?
<?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)
));
}
?>