28 Apr, 2007
WordPress: Make home page show latest post (in the "single post" format)
Posted by: Jennifer In: WordPress|WordPress Bookmarks|WordPress Hacks|WordPress: Lessons Learned
In a custom wordpress theme design I was working on tonight, I was trying to do as the title describes – make the home page show only one post (yes I know there's already a built in way to do this) but I wanted it to show up the same way the single view shows it – with the comments expanded and the comments form visible, etc. If you know of another/better way to do this, please say so in the comments. But this DID do the trick. I found this page in the support archives. The idea was to create your index.php to look like you wanted (ie. exactly like the "single.php" page) but add this before you start the loop:
<?php
$i=0; // Initialize to Zero;
if (have_posts()) :
while (have_posts()) : the_post();
if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
endwhile;
endif;
//get only the latest post
$posts = query_posts( 'p='.$recentpostid."'");
?>
and then you start your loop like you normally would…
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
Worked for me!
Update As Danny pointed out in the comments – there's a simpler way to do this. Put the following code on the page (I put it before the loop and it worked)
<?php $wp_query->is_single = true; ?>
Much simpler