2013-05-13 69 views
0

我顯示框,使用下面的代碼網站的頭版上最新文章:顯示最近的文章的標題爲特定類別

<?php 
    $recent = get_posts('posts_per_page=3'); 
    if($recent) foreach($recent as $post) { 
     setup_postdata($post); ?> 

    <span class="recent-date"><?php the_time('d.m.Y'); ?><br /></span> 
    <span class="recent-title"><?php $limit = 5; $text = get_the_title(); 

    if (str_word_count($text, 0) > $limit) { 
     $words = str_word_count($text, 2); 
     $pos = array_keys($words); 
     $text = substr($text, 0, $pos[$limit]) . '...'; 
    } 
    echo $text; 
?> 

我想要做同樣的事情,但只展來自特定類別的帖子,我該怎麼做?

回答

0

只需調整get_posts參數,例如:

$recent = get_posts('posts_per_page=3&category=5'); 
相關問題