简体   繁体   English

wordpress query_posts打破特色图片

[英]wordpress query_posts breaks featured image

I'm using featured images on a WordPress site on pages (not posts). 我在WordPress网站上的页面(不是帖子)上使用精选图片。 It works fine until I use query_posts in a page template and then the header/branding img reverts to the standard images. 直到我在页面模板中使用query_posts ,然后页眉/品牌img还原为标准图像,它才能正常工作。

This is the code I'm using: 这是我正在使用的代码:

<?php 
query_posts(array('category_name'=>'news-and-features', 'posts_per_page' => 2 ));
while (have_posts()) : the_post(); ?>
  <div class="single-post">
    <h3><a href="<?php echo get_permalink(); ?>"><?php the_title();?></a></h3> 
    <?php the_time('D jS M, Y') ?>
    <?php the_excerpt();?>
</div>
<? endwhile; ?>

The post excerpts display fine. 文章摘录显示良好。 It's just that the query_posts breaks the featured image. 只是query_posts破坏了特色图片。

Has anyone found this also? 有人找到了吗? Or any possible solutions? 或任何可能的解决方案?

I am using a custom child theme and the above is in a template. 我正在使用自定义子主题,以上内容在模板中。

MTIA. MTIA。

您可能需要在此之后添加

<?php wp_reset_query(); ?>

You have not destroyed the query you made with query_post . 您尚未销毁使用query_post进行的查询。

wp_reset_query() should be used to reset the loop. wp_reset_query()应该用于重置循环。 It should be added after your loop, in your case, after the endwhile . 应该在循环之后(在您的情况下)在endwhile之后endwhile

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

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