我使用以下代码查询类别的帖子:
<?php query_posts("cat=8"); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<article>
<h4><?php the_title(); ?> </h4>
<p><?php the_content(); ?></p>
</article>
<?php endwhile; ?>
它似乎工作正常,直到我在一个页面上第三次(上面的代码的三个实例)完成它。现在页面似乎永远加载,它打破就好像它正在编译超过1页面模板。我应该提一下,除非我将帖子发布到第三类
,否则一切正常有没有人有这样的问题,或者知道为什么会这样? 这是查询帖子的不良做法吗?
答案 0 :(得分:2)
请改用WP_query,以便您可以使用wp_reset_postdata来解决问题。
<?php
$the_query = new WP_Query( 'cat=8' );
while ( $the_query->have_posts() ) : $the_query->the_post();
?>
<article>
<h4><?php the_title(); ?> </h4>
<p><?php the_content(); ?></p>
</article>
<?php
endwhile;
wp_reset_postdata();
?>