第一页后Wordpress分页不起作用

时间:2018-07-05 13:36:07

标签: php wordpress

我正在编辑WordPress,并且正在建立具有分页功能的博客页面。

问题是分页在第一页之后不起作用。 如果单击第二页和后续页面,则继续在第一页看到前四篇文章。

PHP代码

    <?php
        $the_query = new WP_Query( array('posts_per_page'=>4,
            'offset' => 1,
            'post_type'=>'post',
            'paged' => get_query_var('paged') ? get_query_var('paged') : 1) 
                        ); 
    ?>

    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
        <div class="c-older-post__wrapper">
            <div class="c-older-event-cover" style=" background-image: url('<?php the_post_thumbnail_url($thumbnail->ID, 'large') ?>')"></div>
            <div class="c-older-event-content">
                <p class="c-events-single-event__date">12 May 2018</p>
                <a href="<?php the_permalink(); ?>" class="file-title">
                <h2><?php echo substr(get_the_title(), 0, 32); ?></h2>
                </a>
                <div><p><?php echo wp_trim_words( get_the_content(), 20, '...' ); ?></p><p>
        <a class="c-internal-link" href="<?php the_permalink(); ?>">link</a></p></div>
            </div>
            <div class="clearfix"></div>
        </div>
    <?php
    endwhile;

    $big = 999999999; // need an unlikely integer
     echo '<div class="pagination">' . paginate_links( array(
        'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
        'format' => '?paged=%#%',
        'mid_size'           => 0,
        'prev_text'          => __('«'),
        'next_text'          => __('»'),
        'current' => max( 1, get_query_var('paged') ),
        'total' => $the_query->max_num_pages
    ) ) . '</div><div class="clearfix"></div>';
                wp_reset_postdata();
            }
    ?>
</div>

0 个答案:

没有答案