Home = Single Blog Post + Comments

This post could have easily been titled “Never work with designers” but hey, let’s move on.

So after documenting my, at least in my opinion, elegant solution to linking to the latest blog post in WordPress Mike changed his mind and decided he would like his latest post complete with comments as his home page. A simple job, right?

index.php would surely do the trick. WordPress treats this file in a special way and sets up the “loop” ready to roll filled with the number of posts you define in the admin area.

First off I thought I could simply include my single.php in index.php and all would be well. The first post would be displayed and we would be set, comments and all – wrong! The post appeared but not the comments.

It’s Easy Really

After much hunting around I came across a really neat WordPress trick. The code snippet below, inserted into my index.php solved the problem. In actual fact this is my entire index.php file.

$wp_query->is_single = TRUE;

First up we tell WordPress that we only want to show 1 post per page. This overrides the setting in the admin.

Next we tell WordPress that we are treating the post as a single post. This then allows us to have access to all the functions related to a single post which is important as we will need these to pull out the comments in the template.

Finally I include my single.php template.

No need to code up a new template, nice and DRY and it achieved the desired result in 3 lines of code.