我有一个wordpress网站,我正在创建。在post页面上,我有允许使用PHP的文本小部件,其中我有一个自定义循环:
<?php $my_query2 = new WP_Query("showposts=1&cat=9,10,11,18,19&orderby=rand"); ?>
<?php if (have_posts()) : ?><?php while (have_posts()) : the_post(); ?>
<a href="<?php the_permalink() ?>">
<div class="home-widget-thumb">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail('home-thumb');
}
?>
</div>
<h2><?php the_title(); ?></h2></a>
<div class="body">
<?php echo get_the_excerpt(); ?>
</div><!--body-->
</br>
<span class="more-link">
<a href="<?php the_permalink() ?>">[more]</a>
</span>
<?php endwhile; ?>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>出于某种原因,无论您在哪个博客上发表文章,都与我创建的循环中的相同。参见这里的一个示例:http://counselingandtraining.com/play-therapy/
没有修改post的循环。
有人能告诉我为什么会这样吗?
如果我能提供更多的信息,请告诉我。
提前谢谢你的时间。克里斯
发布于 2014-05-15 22:47:58
在我看来,问题在于您仍然在使用基本查询。
您可以通过在代码中添加变量$my_query2来改变这一点,如下所示:
<?php if ($my_query2->have_posts()) : ?><?php while ($my_query2->have_posts()) : $my_query2->the_post(); ?>这将使所有函数(如the_title()、the_content()等)按预期工作,因为它们将被设置为$my_query2。
https://stackoverflow.com/questions/23689053
复制相似问题