Wordpress分页 - 帖子数量太多页面

时间:2013-09-25 09:32:47

标签: php wordpress pagination wordpress-theming

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

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我通过将“total' => $total更改为”total' => $dataQuery->max_num_pages,

来解决此问题

答案 2 :(得分: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,
) );