繁体   English   中英

WordPress的query_posts问题

[英]Wordpress query_posts issue

我正在尝试在两个单独的div中显示不同类别的帖子。 第一次使用query_posts,但我认为我没有正确关闭它,因为如果我将第一个div设置为仅显示类别5的帖子,第二个div仅显示类别4的帖子,则它们都会显示来自5的帖子。

我究竟做错了什么?

<!--- START FIRST DIV --->
<div>

<?php if (is_home()) {query_posts("cat=5");}?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div><?php the_post_thumbnail( array(300, 170) ); ?></div>
<div><a href="<?php the_permalink() ?>"><?php the_title(); ?><br />(<?php the_date(); ?>)</a></div>
</article>
</div>

<?php endwhile; ?>
<?php endif; ?>

</div>
<!--- END FIRST DIV -->

<!--- START SECOND DIV --->
<div>

<?php if (is_home()) {query_posts("cat=4");}?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div>
<article <?php post_class() ?> id="post-<?php the_ID(); ?>">
<div><?php the_post_thumbnail( array(300, 170) ); ?></div>
<div><a href="<?php the_permalink() ?>"><?php the_title(); ?><br />(<?php the_date(); ?>)</a></div>
</article>
</div>

<?php endwhile; ?>
<?php endif; ?>

</div>
<!--- END SECOND DIV -->

在第一个循环之后尝试wp_reset_query()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM