编辑:我用\\u posts\\u分页替换了wordpress本机以外的pagenavi。现在我根本没有分页,它只是显示了4篇文章的内容,但没有分页(是的,我在类别中有4篇以上的文章)。有人能帮我弄清楚吗P
有谁能告诉我,为什么分页除了坐在那里看起来很漂亮之外,什么都不做?在添加pagenavi插件之前,我尝试使用\\u posts\\u分页(数组(\'mid\\u size=>2))进行分页显示,但没有输出,也没有分页。现在分页正在显示,但它完全没有任何作用。。。
$categories = get_categories();
foreach ( $categories as $category ) {
if ( $category->name != "Uncategorized" ) {
//****Set attributes
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => 4,
\'category_name\' => $category->name,
\'paged\' => $paged
);
//****Get the posts
$query = new WP_Query( $args );
//****Display the posts
?>
<section class="category_<?php echo $category->name; ?>"><?php
//Category name and number of posts
echo "<p> The name of the category is <span class=\'category_title\'>".$category->name."</span> and the number of posts is ".$category->count."</p>";
echo \'<ul>\';
while ( $query->have_posts() ) {
$query->the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php }
echo \'</ul>\';
the_posts_pagination( array( \'mid_size\' => 2 ) );
</section><?php
//****Reset posts
wp_reset_postdata();
}
}
最合适的回答,由SO网友:anyhylus 整理而成
我终于找到了解决方案:
只需更换此:
the_posts_pagination( array( \'mid_size\' => 2 ) );
使用:
echo paginate_links( array(
\'total\' => $query->max_num_pages,
\'mid_size\' => 2
));