簡體   English   中英

Wordpress 分頁 - 帖子數量過多

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM