首先,不要使用query_posts()
, 使用WP_Query()
相反(Learn More)
与您的WP_Query()
使用paged
参数数组中的参数,如:
<?php
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => 1,
\'paged\' => $paged
);
$cat_query = new WP_Query( $args );
?>
对于分页链接,请使用:
<?php
$total_pages = $wp_query->max_num_pages;
if ( $total_pages > 1 ) { ?>
<div id="nav-below" class="navigation">
<div class="nav-previous">
<?php next_posts_link(__( \'<span class="meta-nav">«</span> Older Entries\', \'your-theme\' )) ?>
</div>
<div class="nav-next">
<?php previous_posts_link(__( \'Newer Entries <span class="meta-nav">»</span>\', \'your-theme\' )) ?>
</div>
</div><!-- #nav-below -->
<?php } //endif ( $total_pages > 1 )
别忘了使用
wp_reset_postdata()
在必要的代码块之后重置查询。