
In WordPress, comment template is normally displayed in a single or page view. However, there might be some specific situation where you want to display the comments on your main page, right underneath your entry, before the next entries.
By default, you will be able to find the comment template tag - <?php comments_template(); ?> inside a single.php and/or page.php. Trying to put that template tag inside your index.php will not going to achieve anything.
Actually, you can. I was looking inside WP’s core file, specifically comment-template.php inside the wp-include folder. This is the fragment of code that we will discuss here.

If you are comfortable with editing the core file, you can just add is_home() together with that is_single() and is_page(). But there is an easier way. Notice the $withcomments variable there? We are going to use it.
Consider we are using the Default WP theme, open your index.php file, and add this line of code
<?php $withcomments = 1 ?>
right after <?php get_header(); ?>
Then add the comment template tag <?php comments_template(); ?> inside the Loop before <?php endwhile; ?>
So the entire index.php file will be like this
<?php get_header(); ?>
<?php $withcomments = 1 ?>
<div id="content" class="narrowcolumn">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
<div class="entry">
<?php the_content('Read the rest of this entry »'); ?>
</div>
<p class="postmetadata"><?php the_tags('Tags: ', ', ', '<br />'); ?> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php comments_template(); ?>
</div>
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php include (TEMPLATEPATH . "/searchform.php"); ?>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
It depends on your theme though. But the foundation is basically the same.
Since the code for comment form is also inside the comment template, so you will also see the comment box at the end of each entry. And when you post a comment using that comment form, the comment will still be posted but you will be directed to the single view.
You can see a (very long) screenshot here.
Well, I think there is a way to remove the comment form, and put in in another file that will only be displayed inside the single/page view. Or anything. So, yeah, try it yourself
Good luck.
89 comments — Post a comment ↓
Bat —
02 Jun 08 / #I see..This is how to make a site that similar to A Brief Message. Although they didn’t use wordpress(I think).
So, Flisterz, maybe you can make one for our local scene.
And, thanks for the article. Really helps a lot for a future reference.
Artgeex —
02 Jun 08 / #thanks for the info. Aku pun dah lama tak baca pasal benda terkini untuk WP. Still using the old tech of WP
btw, aku nak request boleh? Kalau ko dah buat, ko bagi aku link nya ok. Kalau belum, ni requestnya: buat tutorial pasal nak guna image dalam custom field dan appear macam frontpage ko ni. Boleh? Alaaa bolehla (sambil buat muka comel ekekek)
ikram-zidane —
02 Jun 08 / #good tutorial.
actually artgeex, he’s using the one written on derek’s blog..
http://5thirtyone.com/archives/875
custom field is becoming more famous everyday, there’s a lot of tutorials for it.. just google…
flisterz —
02 Jun 08 / #@Bat : Haha yeah I dont think they use WP.
Your welcome Bat
@Artgeex : Rasenye dah lame benda ni ade, ramai x tau je. heh.
@Ikram @Artgeex :
I never read that tutorial before actually, but yeah, it is basically the same thing. A lot of ppl are writing about custom field right. Its a great thing to play with
Artgeex —
02 Jun 08 / #@ikram_zidane: I know I can Google nearly everything, but I visit Flisterz’s blog nearly everyday. That’s why I made the request. Manalah tau, Flisterz got a more easy understanding way ke, kan?
ikram-zidane —
02 Jun 08 / #Lol.. sorry dude.. best assumption/guss based on the look..
okay. there are plenty on the web and the simplest i found was on webdesignerwall.. check it out.. on the sidenote, i beg to differ, i think the understanding is the same all the way.. its the executions that are different.. i like this one http://justintadlock.com/archives/2007/10/24/using-wordpress-custom-fields-introduction and the one on WDW the best..
Artgeex —
03 Jun 08 / #i dont agree with you with the understanding stuff
i simply will walk away with the previous example that you gave me. The codes looks cluttered for someone that cant do programming or a noob, like me. I just hate the font that he used to indicate that it is a bunch of codes.
and I think the new one is more comprehensible.
thanks btw
Cristian Eslava —
08 Jun 08 / #Hi,
First congratulations for your work, great blog.
You can see a very customize template of Wordpress here:
http://justtellmewhy.com
Best regards
dizi izle —
11 Jun 08 / #thanks
Tom —
14 Jun 08 / #Thank you from a complete newbie. It worked perfectly.
Tom
Bransby —
28 Jun 08 / #This has been exceedingly helpful for me, thank you very much. I’m a total noob to php and wordpress, but am RTFM and getting there slowly.
Quick question though, you mention at the end that “And when you post a comment using that comment form, the comment will still be posted but you will be directed to the single view.” How can I stop this from happening? How do I make a comments submission redirect back to the main page? For my purposes the single page view is pretty useless, and I’d like to keep it all on the main page. TIA
B
Bransby —
28 Jun 08 / #Oh, and, I stumbled you, hope that’s ok.
flisterz —
28 Jun 08 / #@Bransby: I’m sorry, I haven’t found the solution for that.
Shaun —
30 Jun 08 / #<!– comments …………………………… –>
<?php $wp_query->is_single = true; ?>
<?php comments_template(); ?>
<!– /comments –>
Dude add this after your post in index.php - so much easier
Jon —
16 Jul 08 / #I’m trying to use this in a current Wordpress install - but it seems this functionality has now been removed from WP2.6 - is anyone else finding this problem?
Bart Lee —
28 Jul 08 / #I also found it didn’t work in 2.6, but editing comment-template.php as described did. Thank you!
Amanda Wray —
29 Jul 08 / #This has been a very valuable post for me in solving the issue of having comments show up on a post page. Worked very well, except that it won’t let me put the comments template inside the loop so I can have it show up after each post.
It give me this error:
Fatal error: Cannot redeclare k2_comment_type_detection() (previously declared in /home/.ceno/wrayco/www.sgvhabitat.org/wp-content/themes/cutline-3-column-split-11/comments.php:15) in /home/.ceno/wrayco/www.sgvhabitat.org/wp-content/themes/cutline-3-column-split-11/comments.php on line 23
Any thoughts?
Ed Atrero —
01 Aug 08 / #Cool… works great! Thanks Flisterz.
jon —
10 Aug 08 / #just wanna check something
jon —
10 Aug 08 / #Hey great tutorial, I just wanted to see if i would be redirected to your main pageafter posting the comment, I just figured out how to put wordpress on my website, but now I want to do what you’ve just demonstrated in your turorial AND redirect to the main page instead of the single page thing wordpress has set up for posted comments - any suggestions anyone? Thanks
Kym —
28 Nov 08 / #I have looked at the script.,
porn —
01 Dec 08 / #Bog thanks for this mega informative website :))
Jenna —
08 Dec 08 / #Wow. Nice site. I like your design. Very, very thanks!
hot —
09 Dec 08 / #Good design and cool themes on this website. Thanks for autor(s)
celebrity —
09 Dec 08 / #Very good website! I add this site to bookmark. Thanks
Another —
17 Dec 08 / #Very good website and very good themes. Thank you master!!! Regards
Ibuprofen —
21 Dec 08 / #Real good website. Thank you master!
Promethazine —
22 Dec 08 / #Good website. I like the all pages and all comments. Thanks for all!!! Regards!!!
Toni —
22 Dec 08 / #Nice website. Very cool content. Thank you!!!
Alien Among Us —
29 Dec 08 / #Awesome dude. I was looking all over for this. Found you from this google search “SHOW COMMENT FORMS ON WORDPRESS MAIN INDEX”
Pranav Shah —
31 Dec 08 / #is there a plugin that does this?
flisterz —
31 Dec 08 / #@Pranav Shah:
I am not sure about that.
New —
11 Jan 09 / #Good website, cool content and design. Big thanks for webmaster.
Marissa —
13 Jan 09 / #Hi. Thanks for showing me how to display comments immediately after a post. Works great, except, do you have any idea why my right sidebar disappears when the comments show?
I also submitted the question to the WP forum, but perhaps you might have the quick answer. Meanwhile, I had to revert until I get an answer.
I use Cutline 3-column, WP 2.6.3. Thanks Bro.
nude —
14 Jan 09 / #Bog thanks for this mega informative website :))
Adriana —
15 Jan 09 / #Hi owner! Cool site. Cool design. Cool comments :))
amateur —
18 Jan 09 / #Good website with wery informative pages. I like it and add this site to bookmarks.
Britney —
25 Jan 09 / #Good thematic website and great design. Big thanks for webmaster!!!
actress —
25 Jan 09 / #Nice…. Cool work and excellent Site! Good source of factual information! Cheers.
Janet —
04 Feb 09 / #Very good and informative website. Thank you webmaster!
whole —
08 Feb 09 / #Nice site! I real happy and impressed with this site!
FegeInnoche —
11 Feb 09 / #exciting and communicative, but would make something more on this topic?
DebbieMahler —
12 Feb 09 / #Sweet! Thank you so much! It worked beautifully! You are awesome!
nick —
12 Feb 09 / #Thanks very much for posting this. I was Googling forever on how to do this.
Alyssa —
14 Feb 09 / #Cool site. I shall visit again and I shall inform my best friends. Thank you!
Victoria —
14 Feb 09 / #Good website and beautiful design!!!!!!!!! Regards!!!!
web —
16 Feb 09 / #Good website and nice content!!! Thank you, master!
buy —
17 Feb 09 / #Very good website. Thank you master!!!!!!!!!!!!!!!!!!!!!!!!!!
Diovan —
18 Feb 09 / #Cool design and very informative site. Thank you mister!
Salma —
21 Feb 09 / #Hi owner! Cool site. Cool design. Cool comments :))
Hayden —
23 Feb 09 / #Good website and nice content!!! Thank you master!
Gisele —
23 Feb 09 / #Good website…. Happy comments ;)…. I can post my link here?
abc —
24 Feb 09 / #how can i put image on the side of my comments ?
military —
25 Feb 09 / #Good website and happy messages. I like it. Thank you master!
Audrina —
25 Feb 09 / #Cool site. I like it. Thank you!
Katja —
28 Feb 09 / #Very informative website. Thank you! +1 bookmark !!!
Racquel —
01 Mar 09 / #Good site!!! Thank you!
Serenity —
02 Mar 09 / #Bog thanks for this mega informative website :))
Eva —
03 Mar 09 / #Good website. I like the all pages and all comments. Thanks for all!!! Regards!!!
Angelina —
04 Mar 09 / #Good website and beautiful design!!!!!!!!! Regards!!!!
Miko —
08 Mar 09 / #Cool design and very informative site. Thank you mister!
Art —
15 Mar 09 / #Thank you for the codes about showing comments on post page; worked perfectly.
Art
Zyrtec —
19 Mar 09 / #Very good website. Thank you webmaster!!! Best regards!!!
Eva —
21 Mar 09 / #Good website. I shall visit again and I shall inform my friends
Abi —
24 Mar 09 / #Very good website! Thank you!
Christina —
24 Mar 09 / #Nice site! I like info from this site. Thank you!
Jennifer —
24 Mar 09 / #Hi all. Goog site and cool design. Big respect for webmaster that make this site!
Jaime —
31 Mar 09 / #Wow. Nice site. I like your design. Very, very thanks!
Tara —
01 Apr 09 / #Good website and very nice comments. Thank you!
Amy —
02 Apr 09 / #Wow. Nice site. I like your design. Very, very thanks!
Sunrise —
03 Apr 09 / #Real nice comments. I want do also. Sorry for comment. I need moneys
Regards!!!!!
Eliot —
04 Apr 09 / #Very interesterd website, I very like all articles and all nnice comments
Thanks
Max —
04 Apr 09 / #Cool site. I shall visit again and I shall inform my best friends. Thank you!
naked —
06 Apr 09 / #Cool website! Best regards and nice day!
intimnyie —
08 Apr 09 / #Good website and very nice comments. Thank you!
Levlen —
08 Apr 09 / #Cool comments. Big thanks for all visitors and for author. I love this site!!!
Amanda —
10 Apr 09 / #Im very like doing this research paper on legalizing pot.
I like information that you
Jaydaloren —
11 Apr 09 / #It’s nice ! Information will help all ! thank you …
Abi —
13 Apr 09 / #Very good website. Thank you master for this all pages!!! Regards!
nudity —
13 Apr 09 / #Very good site! I like it! I just wanted to pass on a note to let you know what a great
Tory —
18 Apr 09 / #Nice website. Very cool content. Thank you!!!
Julia —
18 Apr 09 / #Good work! Excellent Site. Good source of factual information! Cheers.
Ashton —
18 Apr 09 / #Very good website. Thank you master!!!!!!!!!!!!!!!!!!!!!!!!!!
Amanda —
19 Apr 09 / #Hi webmaster! Very good website and very intereted pages!! I love this resource!!! Thank
nayti —
19 Apr 09 / #Good thematic website and great design. Big thanks for webmaster!!!
wine —
27 Apr 09 / #Very good site! I like it! I just wanted to pass on a note to let you know what a great
celebs —
29 Apr 09 / #Nice site! I real happy and impressed with this site!
Thierry —
04 Jun 09 / #excellent article, thank you so much; this is exactly what I was looking for !!
dizi izle —
03 Jul 09 / #ty my admin niceee..