开发者

Featured articles list

开发者 https://www.devze.com 2022-12-12 22:44 出处:网络
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?

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

精彩评论

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

关注公众号