【问题标题】:Pagination link on static page静态页面上的分页链接
【发布时间】:2019-01-30 18:55:21
【问题描述】:

当我直接在 url 中更改页面时,手动分页正在工作。但它不适用于链接,链接始终是第 2 页。

它显示在静态页面上。我将 get_query_var('paged') 更改为 get_query_var('page') 以使分页(手动)工作。

<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 2,
'paged' => ( get_query_var('page') ? get_query_var('page') : 1)
);
query_posts($args);
while (have_posts()) : the_post();
?>
<?php echo get_permalink(); ?>
<?php endwhile; ?>
<?php previous_posts_link( 'Older Posts' ); ?>
<?php next_posts_link( 'Newer Posts' ); ?>

【问题讨论】:

    标签: wordpress pagination


    【解决方案1】:

    你应该使用,new WP_Query($args) 一个例子;

    <?php 
    $args = array(
    'post_type' => 'post',
    'posts_per_page' => 2,
    'paged' => ( get_query_var('page') ? get_query_var('page') : 1)
    );
    // the query
    $the_query = new WP_Query( $args ); ?>
    
    <?php if ( $the_query->have_posts() ) : ?>
    
        <!-- pagination here -->
    
        <!-- the loop -->
        <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <h2><?php the_title(); ?></h2>
        <?php endwhile; ?>
        <!-- end of the loop -->
    
        <!-- pagination here -->
    
        <?php wp_reset_postdata(); ?>
    
    <?php else : ?>
        <p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>
    

    更多详情:https://codex.wordpress.org/Class_Reference/WP_Query

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 2021-08-13
      相关资源
      最近更新 更多