我正在使用一个基本的wordpress循环来显示3篇博客文章+分页,使用query_posts来循环这些-代码附件。循环和分页工作得很好,但它显示了一个奇怪的小故障:整个页面内容(针对所有3个帖子)也被循环和显示。完整内容出现在分页之后、endwhile结束标记之后、所有代码的末尾。
我怀疑这个循环不知何故没有闭合,但我知道要检查的任何结束标记都已经存在。我的php还处于初学者阶段,主要集中在标准的wordpress函数上,所以任何关于我如何结束这篇文章的建议都将受到欢迎。
注意:由于分页的原因,循环使用query_posts而不是new WP_Query,这在使用任何new WP_Query循环时都不起作用。我想去掉额外的内容,但保持基本循环不变,这样分页仍然有效。
最后注意:我已经验证了额外的内容是由这个循环引起的,因为删除循环也会删除内容。
<article class="row">
<?php query_posts(array('posts_per_page' => 3, 'post_type' => 'post', 'paged' => get_query_var('page')));
if (have_posts()) : while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(); ?>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(); ?>
<span class="inline-button">Read more <i class="fas fa-chevron-right"></i></span>
</a>
<?php endwhile; ?>
<?php endif;?>
<?php wp_reset_postdata(); ?>
</article>
<article class="row">
<?php the_posts_pagination(); ?>
</article>
<!------ in html, all extra generated content will appear here below the above article --->
发布于 2020-10-02 00:18:43
解决了!
我找到了答案,并简单地将其关闭,并在末尾添加了以下内容:
<?php wp_reset_query() ;?>
https://stackoverflow.com/questions/64159216
复制相似问题