首页 > 解决方案 > 分页循环仅显示两页

问题描述

我是 wordpress 的最后一名大三学生,想**pagination**用 wp_query 创建,但我只得到 2 页,但是我有 8 个帖子,每页显示 2 个——我在不同的网站上搜索了很多,但没有找到答案

<?php //GET POSTS
            $paged = get_query_var( 'paged' );
            $arr=array(
             'author'         =>the_author_meta('id'),
             'posts_per_page' => 2,
             'paged'          =>$paged,
            );

            $special_query= new WP_Query($arr);//SPECIAL QUERY

            if($special_query->have_posts()){//check if there is posts or no
                while($special_query->have_posts()){
                    $special_query-> the_post();
            /*content*/
            ?>

分页

标签: phpwordpresspagination

解决方案


尝试这个

$query = array(
    'post_type' => 'post',
    'posts_per_page' => 2,
    'author'=>the_author_meta('id'),
    'ignore_sticky_posts' => true,
    'paged' => get_query_var('paged') ? get_query_var('paged') : 1 
);
$loop = new WP_Query($query);

if( $loop->have_posts() ):
    while ( $loop->have_posts() ) : $loop->the_post();
       //postcode
    endwhile;
endif;

$big = 9999; // need an unlikely integer
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
        'format' => '?paged=%#%',
        'current' => max(1, get_query_var('paged') ),
        'total' => $loop->max_num_pages
) );

推荐阅读