开发者

Featured articles list

I'd like to display 10 articles from "featured" category. Only the first should have title and excerpt, the rest 9 only titles. How'd I do that?

Many开发者_StackOverflow thanks for your help.


When you are looping through the posts, just check if current $post in the loop is the first one in the return from the get_posts function:

<?php
    $featured = get_posts('numberposts=10&category_name=featured'); // Your original query

    foreach($featured as $post):
        $first = ($post == $featured[0]);
        setup_postdata( $post );

        if($first): ?>

        <div class="post main-featured">
            <h2><?php the_title(); ?></h2>
            <p><?php the_excerpt(); ?></p>
        </div>

        <?php else: ?>

        <div class="post featured">
            <h2><?php the_title(); ?></h2>
        </div>

        <?php endif;        
    endforeach;
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜