首页 > 解决方案 > Wordpress:页面分页?

问题描述

在 wordpress 站点中,我有一个循环,可以在页面上显示某个类别的帖子。我有一个分页代码。显示分页。但是,如果我转到第 2、3、4 页……显示的结果始终是第一页。有人看到错误吗?

谢谢你的帮助。我看不到错误。

我的代码:

<a class="xyz" href="<?php the_permalink(); ?>"></a>
<h3 class="entry-title"><?php the_title(); ?></h3>

<?php 
if ( has_post_thumbnail() ) {
    the_post_thumbnail('medium');
} 
?>

<?php the_excerpt(); ?>
</div><!-- grid-item -->



<?php
      endwhile; 

       $total_pages = $tk_specials_querie->max_num_pages;
       if ($total_pages > 1){

        $current_page = max(1, get_query_var('page'));

         $paginate_links =  paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => '/page/%#%',
            'current' => $current_page,
            'total' => $total_pages,
             'show_all'        => False,
            //'end_size'        => 1,
            // 'mid_size'        => $pagerange,
             'prev_next'       => True,
             'type'         => 'plain',
             'end_size'     => 1,
             'mid_size'     => 2,
            'prev_text'    => __('« prev'),
            'next_text'    => __('next »'),
             'type'            => 'plain',
        'add_args'        => false,
        'add_fragment'    => ''
        ));
    }  
    ?>

<?php
else :
  esc_html_e( 'Derzeit keine Beiträge!', 'text-domain' );
endif;
 wp_reset_postdata();
?>

标签: phpwordpress

解决方案


好的,我现在做到了。如果有人想知道如何:


             <div class="grid" data-masonry='{ "itemSelector": ".grid-item", "columnWidth": 445, "gutter": 20 }'>




                <?php
                    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
                    $query = new WP_Query( array(
                        'post_type'   => 'post',
                        'post_status' => 'publish',  
                        'posts_per_page'         => '50',
                        'paged'                 => $paged,
                        'order'                  => 'DESC',
                        'orderby'                => 'date',
                        'cat'                    => '949',
                    ) );
                ?>

                <?php if ( $query->have_posts() ) : ?>

                <!-- begin loop -->
                <?php while ( $query->have_posts() ) : $query->the_post(); ?>

                   <div class="grid-item">
                        <a class="xyz" href="<?php the_permalink(); ?>"></a>
                        <h3 class="entry-title"><?php the_title(); ?></h3>

                        <?php 
                            if ( has_post_thumbnail() ) {
                            the_post_thumbnail('medium');
                            } 
                        ?>
                    </div><!-- grid-item -->

                <?php endwhile; ?>
                <!-- end loop -->


                <div class="tk_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', __( '<', 'text-domain' ) ),
                            'next_text'    => sprintf( '%1$s <i></i>', __( '>', 'text-domain' ) ),
                            'add_args'     => false,
                            'add_fragment' => '',
                        ) );
                    ?>
                </div>

                    <?php wp_reset_postdata(); ?>

                    <?php else : ?>
                        <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
                    <?php endif; ?>


                </div>

推荐阅读