我对wordpress编码很新,但不是PHP。但我不太了解这里发生的事情。代码是:
<div class="ul-box floatRight">
<ul>
<?php
wp_reset_query();
$index_query = new WP_Query(array( 'post_type' => 'explore_more', 'posts_per_page' => 3,'order'=>'DES' ));
?>
<?php
while ($index_query->have_posts()) : $index_query->the_post(); ?>
<li class='spotlight-li'>
<?php the_post_thumbnail(); ?>
<div class="explore-more-content floatLeft">
<h4><?php
$title=get_the_title();
echo showBrief($title,8);
?></h4>
</div>
</li>
<?php
endwhile;
wp_reset_query(); ?>
</ul>
</div>
出于我之外的原因,它正在制作重复的帖子。我已多次用Google搜索,据我所知,某处有一个双循环,但我不知道在哪里。我只能看到while
循环,除非get_the_title()
函数或showBrief()
函数中有更多循环。
有人可以帮忙吗?
答案 0 :(得分:2)
您的代码似乎很好并且应该按预期工作,但是,showBrief()
不是本机Wordpress功能。这非常特定于您的主题,因此您需要深入研究主题代码并检查该功能的确切功能。在不知道该功能究竟是什么的情况下,我不能告诉你这是不是你的问题。
但是我对你的代码有一些注意事项:
'order'=>'DES'
应为'order'=>'DESC'
在查询之前,您不需要wp_reset_query();
。主查询已经自行重置,所有自定义查询都应重置
wp_reset_query();
应为wp_reset_postdata();
。 wp_reset_query();
与query_posts
一起使用,从不
而不是使用:
和endwhile
,而是使用curlies({}
)。是的,您的语法是100%正确的,但很难调试,因为代码编辑器不支持该语法。所有代码编辑器都支持curlies,这使得调试变得轻而易举