精选文章列表

时间:2009-11-28 12:04:02

标签: wordpress list featured

我想在“精选”类别中展示10篇文章。只有第一个应该有标题和摘录,其余9个只有标题。我怎么做到的?

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:2)

当您浏览帖子时,只需检查循环中的当前$post是否是get_posts函数返回的第一个:

<?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;
?>
相关问题