I'm working on a theme homepage and would like to include an excerpt from the latest post in a specific category. In this case, the category slug is "gear". I've tried a couple options with
WP_Query but am unable to get it to return only one post.
Here's my current code:
<?php $latest1 = new WP_Query(); $args=array('category_name=gear','posts_per_page=1'); $latest1->query($args); while ($latest1->have_posts()) : $latest1->the_post(); ?> <h1 class="home-article-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <div class="storycontent"> <?php the_excerpt(); ?> </div> <?php endwhile; wp_reset_query(); ?>
There are currently two posts in the "gear" category, and both are being returned. I must be misunderstanding the posts_per_page option.
If there's a better way to do this than WP_Query (making this call three times on the page, once for each category), I'm open to that as well.