0

I'm displaying a box with recent posts on the front page of a site using the following code:

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

I want to do the exact same thing, but only show posts from specific category, how do I do this?

4

1 回答 1

0

只需调整get_posts参数,例如:

$recent = get_posts( 'posts_per_page=3&category=5' );
于 2013-05-13T11:41:59.650 回答