我需要显示分类id后,第5和第10位单独的帖子。我搜索了一个查询,查询显示,
<?php $postnum++;
if ($postnum == 5) { ?>
<div class="block">
<h2>Blog</h2></div>
<?php }
if ($postnum == 10) { ?>
<div class="block"><h2>References</h2></div>
<?php }在将上面的代码放在endwhile之前之后,我可以看到位于第5位和第10位的博客和参考资料。但是在插入时,
<?php $postnum++;
if ($postnum == 5) { ?>
<div class="block">
<?php
query_posts( array(cat=>3, orderby=>post_date, order=>desc) );
while ( have_posts() ) : the_post();
?>
<?php the_title();
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<?php }
if ($postnum == 10) { ?>
<div class="block"><?php
query_posts( array(cat=>4, orderby=>post_date, order=>desc) );
while ( have_posts() ) : the_post();
?>
<?php the_title();
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
<?php } </div>
<?php }上面的代码似乎不能正常工作。请大家帮帮我..
发布于 2014-04-15 18:34:03
可能有几件事。检查你的服务器日志,但至少
<?php the_title();
<?php endwhile; ?>错误-要么需要在the_title();之后添加?>,要么在endwhile;之前删除<?php
类似地,这是:
<?php } </div>看起来好像少了一个?>。
为了清楚起见,我可能还会在query_posts()参数两边加上引号:
query_posts( array('cat'=>3, 'orderby'=>'post_date', 'order'=>'desc') );我也阅读了this,这样您就可以确信query_posts是适合您的正确方法。
https://stackoverflow.com/questions/23080201
复制相似问题