【问题标题】:Wordpress Recent Posts excerpt in sidebar is pulling the page/post excerpt instead of the recent post excerpt侧边栏中的 Wordpress 最近帖子摘录正在拉动页面/帖子摘录而不是最近的帖子摘录
【发布时间】:2010-08-19 03:13:31
【问题描述】:

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

知道为什么它会提取正确的标题/作者,但摘录不正确吗?

【问题讨论】:

    标签: wordpress


    【解决方案1】:
    <?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();
    ?>
    

    未设置邮政数据。这些函数提取除 $post 之外的全局值(例如 $ID)。 setup_postdata() 设置所有正确的值。另外,我建议在此之后重置查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多