2010-08-18 149 views
2

我有一个Wordpress博客的边栏中的最近的帖子列表。标题和作者正确显示,但显示的摘录是当前页面/帖子的摘录而不是相关最近的帖子。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; ?> 

任何想法,为什么它会拉动正确的标题/作者,但不正确的摘录?

回答

4
<?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_postdata()设置所有正确的值。另外,我建议在此之后重新设置查询。

+0

太棒了,谢谢! – christina 2010-08-18 19:19:36

相关问题