Alan Edwardes

Display One Latest Post On Your WordPress Homepage

Old Content Warning

This post is very old (it was published 5 years ago), so I can't vouch for its content or accuracy. It may be here for posterity. Please take its content with a pinch of salt.

There is a way to do it without hacking your theme - Settings -> Reading - > Blog pages show at most [X] Posts. The downside to this setting is that it affects archive pages and search pages too, which is mega suckage.

To just display the latest post on your homepage, change the "while" statement to an "if" statement. So, instead of:

<?php while (have_posts()) : the_post(); ?>
[ Post Stuff ]
<?php endwhile; ?>

...with:

<?php if (have_posts()) : the_post(); ?>
[ Post Stuff ]
<?php endif; ?>

I've changed the "while" on the first line to "if", and to close it i've changed the "endwhile" to "endif". How does this work? Well, the while statement continues to print posts on your hompage until it exhausts the post data it's given from WordPress with a loop, the if statement just prints the first post it's given from the data because it's not told to carry on; there is no loop.

21st of September 2008 at 10:33 AM

4 years, 9 months ago

I was 16 years old when I wrote this

164 words

rand: Backing Your Server Up To ...

next: Blog Neglect

prev: The Upcoming Redesign

share:FacebookTwitterRedditdiggStumbleUpondeliciousHacker NewsLinkedIn

Add a Comment

© 2006 – 2013 Alan Edwardes / Source on GitHub
Top