【问题标题】:Use WP_Query, but keep pagination使用 WP_Query,但保持分页
【发布时间】:2012-04-11 04:12:39
【问题描述】:

我想让我的页面显示 2 个最近的帖子,所以我使用 WP_Query 并将 posts_per_page 设置为 2,效果很好,但它会破坏分页。这是我的代码。如何更改它以显示两个最近的帖子并保持分页?

  <?php $wp_query = new WP_Query( array( 'posts_per_page' =>2 ));?>

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

  <?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>


<div <?php post_class() ?> id="post-<?php the_ID(); ?>">

    <div id="ind_post">

        <h2 class="post-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>


        <div id="entry">
        <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>

            <p><?php the_excerpt(); ?></p>
        </div>
        <h4 class="more-post"><a href="<?php the_permalink() ?>">continue reading…</a></h4>

    </div>

<?php endwhile; ?>



<?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

    <?php else : ?>

    <h2>No results found</h2>

<?php endif; ?>
        <?php wp_reset_query(); ?>

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    应该这样做

    <?php $wp_query = new WP_Query( array( 'posts_per_page' =>2, 'paged=' . get_query_var( 'page' ) ));?>
    

    【讨论】:

      猜你喜欢
      • 2023-04-01
      • 1970-01-01
      • 2015-05-21
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多