35 | Front Page Comments on your WordPress Blog
You want to show the comments to the posts on the front page of your blog?
You want to allow visitors to your blog to leave a comment on the latest post without having to click on the comments link or the post title?
You think this should be straight forward and easy to do?
But far from it…
First step is to locate the template file that shows your front page: in most cases,
this is index.php (but it could also be home.php, or any page template that was set to be shown on the front).
Second step is to add comments_template( ”, true ); within the loop, after the_content(), and maybe after any postmetadata.
However, this is not enough, because the wordpress template tag comments_template() has some check build-in, to make sure that comments are normally only be displayed either on a single article or page.
Find this in /wp-includes/comment-template.php line 858:
if ( !(is_single() || is_page() || $withcomments) || empty($post) )
return;
The code provides the use of a global variable $withcomments that can be set to boolean true (or 1) to allow the display of comments.
Putting it all together, here is what to add into your font page template where you want the comments and comments form to show:
<?php global $withcomments; $withcomments = true;
comments_template( '', true ); ?>
For those, who find the structure of the new wp3 default theme TwentyTen difficult to work with, here a direct pointer:
you will find the code to edit in loop.php after line 135:
<div class="entry-content">
<?php the_content( __( 'Continue reading <span class="meta-nav">→</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php global $withcomments; $withcomments = true;
comments_template( '', true ); ?>
