我在尝试分页以便在我正在工作的网站的主页上工作时遇到问题。
“较旧”和“较新”链接正确显示,并且它更新了URL以反映页码,但帖子内容与翻页时的内容保持不变。这是我正在使用的代码,当然是经过简化的:
if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); }
elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); }
else { $paged = 1; }
$get_featured_posts = new WP_Query( array(
'posts_per_page' => 9,
'post_type' => 'post',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
'paged' => $paged,
'offset' => 5
) );
while( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
<h3 class="entry-title entry-added">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute();?>"> <?php the_title(); ?></a>
</h3>
<p class="short_description"><?php echo short_description('...', 16); ?> </em></p>
<p class="read_more"><a href="<?php the_permalink(); ?>">Read More</a></p>
<?php
endwhile;
?>
<?php
// Reset Post Data
wp_reset_query();
?>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
似乎无法弄清楚问题出在哪里,任何帮助将不胜感激。
通过WordPress交流平台上的@milo找出了问题所在。事实证明,使用“偏移”和分页时需要特别注意。检查此链接以获取更多详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句