WordPress分页问题:页面持续空白

时间:2020-05-28 10:04:13

标签: php wordpress pagination

我的自定义Wordpress主题面临一个奇怪的问题...我正试图在我的存档中进行分页,该文档有8页...但是当我转到第7或8页时,什么也没有显示...

我试图删除该分页,然后有 53个帖子。我想每页显示 7个帖子,所以53 / 7 = 7.57的页面数正确。

有我的代码:

<?php
    $text_length = 80; 
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $args = array (
        'post_type' => 'my_custom_post',
        'posts_per_page' => '7',
        'paged'=>$paged
    );
    $query = new WP_Query( $args );
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post(); ?>
            <section>
                <?php if(has_post_thumbnail(get_the_ID())){ ?>
                    <div class="thumbnail">
                        <a href="<?php echo esc_url(get_permalink()); ?>">
                            <?php echo get_the_post_thumbnail(get_the_ID(), 'medium'); ?>
                        </a>
                    </div>
                <?php } ?>
                <div class="content">
                    <h3>
                        <a href="<?php echo esc_url(get_permalink()); ?>"><?php the_title(); ?></a>
                    </h3>
                    <small><?php the_date('d F Y');?></small>
                    <p><?php echo mb_strimwidth(wp_strip_all_tags( get_the_content() ), 0, $text_length, '...');?></p>
                </div>
            </section>
        <?php }
    }
?>
<div class="pagination">
    <?php 
        echo paginate_links( array(
            'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
            'total'        => $query->max_num_pages,
            'current'      => max( 1, get_query_var( 'paged' ) ),
            'format'       => '?paged=%#%',
            'show_all'     => false,
            'type'         => 'plain',
            'end_size'     => 2,
            'mid_size'     => 1,
            'prev_next'    => true,
            'prev_text'    => sprintf( '<i></i> %1$s', __( 'Newest', 'text-domain' ) ),
            'next_text'    => sprintf( '%1$s <i></i>', __( 'Older', 'text-domain' ) ),
            'add_args'     => false,
            'add_fragment' => '',
        ) );
        wp_reset_postdata();
    ?>
</div>

我做错什么了吗?

0 个答案:

没有答案