【问题标题】:wordpress query_posts breaks featured imagewordpress query_posts 打破特色图片
【发布时间】:2012-12-05 04:03:13
【问题描述】:

我在 WordPress 网站的页面(不是帖子)上使用精选图片。直到我在页面模板中使用 query_posts 然后标题/品牌 img 恢复为标准图像,它才能正常工作。

这是我正在使用的代码:

<?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; ?>

帖子摘录显示正常。只是query_posts 破坏了特色图片。

有没有人也发现了这个?或者任何可能的解决方案?

我正在使用自定义子主题,以上内容在模板中。

MTIA。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    你可能需要在 endwhile 之后添加这个

    <?php wp_reset_query(); ?>
    

    【讨论】:

      【解决方案2】:

      您尚未销毁您使用query_post 进行的查询。

      wp_reset_query() 应该用于重置循环。它应该在你的循环之后添加,在你的情况下,在endwhile之后。

      【讨论】:

        猜你喜欢
        • 2019-07-31
        • 2015-04-28
        • 2015-07-17
        • 2014-05-13
        • 2014-11-22
        • 2015-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多