Display Comment Form on Main Index in WordPress


If you want to add a comment form on your main index page in WordPress, do the following:

  1. Open your theme’s index.php file. (e.g., /wp-content/themes/whatever/index.php)
  2. Find this line:
    <?php endwhile; ?>
  3. Add these lines immediately above said line:
    <?php $withcomments = 1; ?>
    <?php comments_template(); ?>

That’s all there is to it.

, ,

  1. #1 by a1000jewels at November 11th, 2008

    You are a legend – thanks – I have been searching to find out how to always display a comments form on pages – and this answered it!
    Many thanks
    Julie P

  2. #2 by a1000jewels at November 12th, 2008

    However – now I have the same comment on all the pages!!
    If you can help, please feel free to do so!
    Thanks
    J

  3. #3 by clifgriffin at November 12th, 2008

    I’m not sure I understand the problem. What do you mean by “same comment on all the pages”?

    A quick look at your site seems to indicate you now have a comment form on your main index page.

  4. #4 by Sophia at November 13th, 2008

    You are a lifesaver! I had been combing the web for a few hours for this to work. I was so determined. Thank you so much.

  5. #5 by Fernando at November 26th, 2008

    perfect, just what i needed : )

  6. #6 by wasabi at December 4th, 2008

    You are great!!!! ;)

  7. #7 by wasabi at December 8th, 2008

    Quick question..I receive a lot of comments in my blog. Do you know a way to setup paging for the comments located in my main page?

    • #8 by clifgriffin at December 8th, 2008

      That is a good question. In short, it’s possible, but you’ll probably have to install a plugin that sets up paging for all comments. WordPress 2.7 can do comment paging natively, but it requires theme changes if you have a 2.6 and before theme.

      If you do not want paging on single pages and just want it on the main index, you’ll have to do something fancy. I’ll take a look at WordPress 2.7 and see if there is an easy way to do this soon. (This blog is currently running 2.7, I haven’t looked at how it does its paging closely yet, however)

    • #9 by clifgriffin at December 8th, 2008

      One more thing: http://ottodestruct.com/blog/2008/09/29/wordpress-27-comments-enhancements/

      This site was very helpful in my conversion to a WordPress 2.7 compatible theme.

  8. #10 by Jeff Brock at January 6th, 2009

    THANK YOU! This saved me from a lot of client-induced anxiety! :)

  9. #11 by Analiese at January 18th, 2009

    I used your fix to display posts along with their comments on my main blog page. Thanks! One issue arose, when I tested the comment form, I discovered that the tab key doesn’t work sequentially. Instead of advancing to the next field in the comment form, it jumps to another field in a different post’s comment form on the same page. I searched online and couldn’t even find someone with the same problem. Any ideas? Thanks!

  10. #12 by Wiffilbofophy at February 10th, 2009

    exciting and informative, but would be suffering with something more on this topic?

  11. #13 by T at February 15th, 2009

    thanks i really appreciate the info as this seems strangely hard to find across the net. i just recently came across the same thing here: http://www.flisterz.com/2008/06/02/wordpress-display-comments-on-main-page/

    but what i am really interested in now is: how can i get only the comments to show, and not the comment input box (the “reply” form)? if people want to leave comments, they can do so on the single post page, but the reply box after every post on the main index really clutters everything up. thanks!

    • #14 by clifgriffin at February 15th, 2009

      I’m not sure, honestly. You might try removing the comments template line and leaving withcomments set to 1. That may or may not work…never tested it.

  12. #15 by Maureen at March 1st, 2009

    Thank you so much for this post! I have spent so much time trying to figure out how to do this.

  13. #16 by swertres at March 5th, 2009

    It works! Thanks…. I have been looking for this for ages!

  14. #17 by Dave at March 11th, 2009

    Thank you Thank you Thank you!!!

  15. #18 by sv3tlio at March 17th, 2009

    Than you! This tip is very useful for me.

  16. #19 by Raju at March 19th, 2009

    Looks so simple, but never knew how to do it. thanks!!

  17. #20 by Angela at March 23rd, 2009

    You rock.

  18. #21 by amy at March 31st, 2009

    Thanks so much! This was very very helpful!

  19. #22 by Will D. White at April 23rd, 2009

    Thank you so much!

  20. #23 by paul at April 27th, 2009

    Thanks! This solved my problem just fine!!!

  21. #24 by wisecat74 at May 1st, 2009

    Thanks man.

  22. #25 by Michael Montgomery at June 11th, 2009

    Thank’s for this piece of advice, I even solved a single.php template page issue with this code.

  23. #26 by Adam Solo at August 9th, 2009

    Great! I was desperatly looking for a way to resolve this.
    Thanks alot!

  24. #27 by sai at August 11th, 2009

    hey, mr. guru,

    THANKS so much, i was searching for this until 5am in the morning.

    article after article, video after video, trying whatever to get this to work.

    finally i came accross u. just add 2 sentence…

    thanks so much,

    i didn’t work right away. i had 2 comment boxes. i don’t know why but i did this and now it works.

    i add the more time on top just for the sake of trying and then it worked i dont know why

    so thanks Much

  25. #28 by cubrikaska at October 3rd, 2009

    Esta idea excelente tiene que justamente a propГіsito

  26. #29 by shaquibkhan at November 21st, 2009

    Thanks Dude….

  27. #30 by Greedysnob at January 6th, 2010

    THANK YOOOOU! YOU ARE THE EFFING BEST DUDE!

    Honestly ive been looking all over for a code that does this! Most of what i found were way too complicated to attempt without screwing up my code…or they were plugins that didnt work.

    THIS WAS SO SIMPLE AND IT WORKED! I LOVE YOU!

  28. #31 by Greedysnob at January 6th, 2010

    I have a quick question. My blog is new, but once it gets popular, it might start getting a lot of comments and I dont want people to have to scroll through all of the comments before they get to the next post. Is there a way to leave the comments box showing, but hide the comments themselves..and maybe have it where they have to click “show comments” in order to see the comments? I love having the comments box on the main page, but i dont want the main page to be flooded with comments.

  29. #32 by Christinamsr at January 31st, 2010

    I have found it on this website called tip swift. You can find it there.
    cheers
    edit: wrong thread,

  30. #33 by haink at January 31st, 2010

    Through our connections cash advance payday you can apply fo. I didn39t have any other option for emergency cash and I39m very grateful. Cash-strapped people are all alike. Ace Cash Advance Cedar Rapids Ia – check cash advance sheffield illinois 4. nationwide cash advance LISA NEAL How does the University of Phoenix online program relate to the. I was going to use some cash and cheques but hope to rely on my Meastro Keycard.

  31. #34 by Matt sich at January 31st, 2010

    where do I put this if I want it only when someone presses a post and goes to it? single.php? I’ve tried it but it never shows up

    • #35 by Matt sich at January 31st, 2010

      ok, I got it to work but now it messed up my xhtml BG. =/

  32. #36 by Drexel at February 24th, 2010

    Great Code. However I get the same comment over and over again for different posts. For some reason it is not rotating comments along with the post?

    Do you have any suggestions?

  33. #37 by Drexel at February 24th, 2010

    Great Code. However I get the same comment over and over again for different posts. For some reason it is not rotating comments along with the post?

    Do you have any suggestions?

  34. #38 by michael at March 10th, 2010

    Thaks

  35. #39 by Naki at May 4th, 2010

    It works. I thank you.

  36. #40 by LG at June 29th, 2010

    Can’t seem to find that line of code in the default theme of WordPress 3. Maybe it’s somewhere else?

  37. #41 by hermes handbags at July 6th, 2010

    in /nfs/c03/h03/mnt/53109/domains/clifgriffin.com/html/wp-content/plugins/search-unleashed/models/highlighter.php on line 169

    Reply Quote

  38. #42 by Dilza at July 27th, 2010

    I really liked your site , I love news like this site that people voted on the team of people to choose the greatest team twitter and compete for prizes http://www.twitorcida.com.br

(will not be published)