侧边栏中的Wordpress最近的帖子摘录正在拉取页面/帖子摘录,而不是最近的帖子摘录

侧边栏中的Wordpress最近的帖子摘录正在拉取页面/帖子摘录,而不是最近的帖子摘录,wordpress,Wordpress,我在Wordpress博客的边栏上有一个最近的帖子列表。标题和作者正确显示,但显示的摘录是当前页面/帖子的摘录,而不是相关的最近帖子 守则: <?php $myposts = get_posts('numberposts=10&offset=0'); foreach($myposts as $post) :?> <li><a href="<?php the_permalink(); ?>"><?php the_title()

我在Wordpress博客的边栏上有一个最近的帖子列表。标题和作者正确显示,但显示的摘录是当前页面/帖子的摘录,而不是相关的最近帖子

守则:

 <?php $myposts = get_posts('numberposts=10&offset=0');
  foreach($myposts as $post) :?>
  <li><a href="<?php the_permalink(); ?>"><?php the_title();?> <span>by <?php the_author(); ?></span></a> <br /> <?php the_excerpt(); ?></li>
  <?php endforeach; ?>


  • 你知道为什么它的标题/作者是正确的,但摘录是错误的吗?

    
    
    <?php $myposts = get_posts('numberposts=10&offset=0');
      foreach($myposts as $post) :
      setup_postdata($post); ?>
      <li><a href="<?php the_permalink(); ?>"><?php the_title();?> <span>by <?php the_author(); ?></span></a> <br /> <?php the_excerpt(); ?></li>
      <?php endforeach;
      wp_reset_query();
    ?>
    

  • 未设置Postdata。这些函数除了$post(例如$ID)之外还拉取全局值
    setup\u postdata()
    设置所有正确的值。此外,我建议在此之后重置查询