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 thanks for your help.
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 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;
?>