2010-08-18 154 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

相關問題