[英]Wordpress Pagination - Too many pages for number of posts
我在我的 Wordpress 主题中为自定义帖子类型添加了分页。 除了它在分页菜单中为帖子数量显示太多页面之外,它效果很好: http : //www.electrickiwi.co.uk/testimonials/
当前应该有 7 页,但显示 12 页。下面的代码是我用来显示分页的代码。 在functions.php 文件中没有与此相关的任何内容。
<?php
/* ------------------------------------------------------------------*/
/* PAGINATION */
/* ------------------------------------------------------------------*/
//paste this where the pagination must appear
global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ($total > 1) {
// get the current page
if (!$current_page = get_query_var('paged')) {
$current_page = 1;
}
// structure of "format" depends on whether we're using pretty permalinks
if (get_option('permalink_structure')) {
$format = 'page/%#%/';
}
else {
$format = 'page/%#%/';
}
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total,
'mid_size' => 4,
'type' => 'list'
));
}
?>
从传递给 paginate_links 的数组中删除'total' => $total
部分,以便自动计算页数。
我通过将 ' total' => $total
更改为 ' total' => $dataQuery->max_num_pages,
我遇到了完全相同的问题,但能够通过使用 'total' => $my_query->max_num_pages 来解决它,如下所示:
$args[ 'post_type' ] = array('resources', 'case_study');
$args['post_status'] = 'publish';
$my_query = new WP_Query( $args );
echo the_posts_pagination( array(
'mid_size' => 3,
'total' => $my_query->max_num_pages,
) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.