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

まったく同じことをしたいのですが、特定のカテゴリの投稿のみを表示するにはどうすればよいですか?

4

1 に答える 1

0

get_postsパラメータを調整するだけです。

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