Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress分页-文章数量过多_Php_Wordpress_Pagination_Wordpress Theming - Fatal编程技术网

Php Wordpress分页-文章数量过多

Php Wordpress分页-文章数量过多,php,wordpress,pagination,wordpress-theming,Php,Wordpress,Pagination,Wordpress Theming,我在我的Wordpress主题中添加了自定义帖子类型的分页。它工作得很好,除了在分页菜单中显示过多的页面以显示帖子数量外: 目前应该有7页,但显示的是12页。下面的代码是我用来显示分页的代码。functions.php文件中没有与此相关的内容 <?php /* ------------------------------------------------------------------*/ /* PAGINATION */ /* ---------------------------

我在我的Wordpress主题中添加了自定义帖子类型的分页。它工作得很好,除了在分页菜单中显示过多的页面以显示帖子数量外:

目前应该有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_链接的数组中删除'total'=>$total部分,以便自动计算页数。

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

谢谢你的回答。当我删除它时,它只是从页面中完全删除分页。