请让我知道为什么Next和Previous Post链接不能处理以下代码?我试图一次只显示一个帖子.我试图检查不同的帖子,但无法找到类似于我的东西.请指导......
<?php
$args = array( 'numberposts' => 1 );
$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div>
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
</div>
<?php the_content(); ?>
<?php endforeach; ?>
<?php comments_template(); ?>
<nav id="nav-posts">
<div class="prev"><?php next_posts_link('PREVIOUS POSTS'); ?></div>
<div class="next"><?php previous_posts_link('NEXT POSTS'); ?></div>
</nav>
Run Code Online (Sandbox Code Playgroud)
我想我和你有同样的问题,只需添加这个就可以使链接转到previous_post_link或next_post_link
<?php previous_post_link( '%link','Previous' ) ?>
<?php next_post_link( '%link','Next' ) ?>
Run Code Online (Sandbox Code Playgroud)
祝你好运