duanshang3230 2013-01-19 21:02 采纳率: 100%
浏览 26
已采纳

Wordpress query_posts问题

I'm trying to show posts from a different category in two separate divs. First time I've used query_posts, but I think I'm not closing it properly or something, because if I setup the first div to show posts only from category 5, and the second to show posts only from category 4, they will both show posts from 5.

What am I doing wrong?

<!--- 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 -->
  • 写回答

1条回答 默认 最新

  • duanmei1946 2013-01-19 21:07
    关注

    try wp_reset_query() after the first loop.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效