Replaced by a fibre glass rhino | The website of Welsh web designer Dan Davies

Back to the blog or the homepage

WordPress post excerpt on a static homepage?

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Back to the blog or the homepage