开发者

Wordpress Recent Posts excerpt in sidebar is pulling the page/post excerpt instead of the recent post excerpt

I have a list of Recent Posts in the sidebar of a Wordpress blog. The title and author show up properly, but the excerpt that gets shown is the excerpt of the current page/post not 开发者_StackOverflowthe relevant recent post.

The code:

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

Any idea why it would be pulling the correct Title/Author, but incorrect excerpt?


<?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 isn't set up. Those functions pull the global values besides $post (e.g. $ID). setup_postdata() sets all the right values. Also, I'd suggest reseting the query after this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜