1

我在我的 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'
    ));
}
?>
4

3 回答 3

0

我通过将 ' 更改total' => $total为 ' 来解决这个问题total' => $dataQuery->max_num_pages,

于 2013-09-26T07:54:37.523 回答
0

从传递给 paginate_links 的数组中删除'total' => $total部分,以便自动计算页数。

于 2013-09-25T09:37:53.070 回答
0

我遇到了同样的问题,但能够通过使用 '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,
) );
于 2021-07-21T21:41:02.563 回答