2015-08-13 105 views
0

所以我有問題,我無法解決。我想獲取發佈數據,如標題和摘錄。但是當我使用我的代碼時,它只顯示最後一篇文章的摘錄,其他所有文章都有正常的內容。所以我希望所有帖子都有摘錄。the_excerpt only only last post

<div class="postai"> 
<div class="postu_pavadinimas"></div> 

<ul> 
<?php 
$args = array('posts_per_page' => 6); 
$lastposts = get_posts($args); 
foreach ($lastposts as $post) : setup_postdata($post); ?> 
    <li> 
     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
     <?php the_excerpt();?> 
    </li> 
    <?php endforeach; 
    wp_reset_postdata(); ?> 
</div> 
</ul> 

編輯: OK 1個觀察,當我改變最多的職位爲3,我不得到任何摘錄可言,只有正常的內容。當我更改爲'posts_per_page'=> 8,第6和第8帖有摘錄。我現在有點困惑....

+0

夥計們,我現在知道問題了。不知何故,我在帖子中的文字已被破壞,摘錄將其識別爲一個符號。感謝您試圖幫助:) – Tomas

回答

1

嘗試使用get_the_excerpt如果它工作。讓我知道

<div class="postai"> 
<div class="postu_pavadinimas"></div> 

<ul> 
<?php 
$args = array('posts_per_page' => 6); 
$lastposts = get_posts($args); 
foreach ($lastposts as $post) : setup_postdata($post); ?> 
    <li> 
     <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> 
     <?php echo apply_filters('the_excerpt', get_the_excerpt()); ?> 
    </li> 
    <?php endforeach; 
    wp_reset_postdata(); ?> 
</div> 
</ul> 
+0

感謝您的迴應,嘗試過這個功能,但現在它只顯示標題,並沒有來自帖子的數據。 – Tomas

+0

使用更新後的代碼 – MKD

+0

使用echo打印exerpts – MKD