Dan Davies{ Front-end Developer }

WordPress post excerpt on a static homepage?

18th November 2011

My homepage isn’t a blog but I wanted to display the most recent post to hook people in. After much searching, I came across the following code. Now I’m not a PHP developer, I know very little so if you can improve on the code, please comment.

<?php $temp_query = $wp_query; ?>
<?php query_posts('category_name=standard&showposts=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>

The only changes I’ve made from the original code is the second line

<?php query_posts('category_name=standard&showposts=1'); ?>

Basically add the category name you want and how many posts you want.

I hope that is of help.

Back to top