Display comments but not comments form on homepage
-
I have solved this problem but in a very clumsy way and I was wondering if there was a more elegant solution.
The problem I would like to display the latest ten posts on my homepage with any associated comments fully displayed under each post. I do not however want ten comment forms on my homepage. I would like the comment form to only be visable when the user views a post as a single post. My site is https://www.langhofc.com if that makes it clearer.
The (clumsy) solution Searching through the forums I have found the following method to display comments on the homepage.
1.Open /wp-includes/comment-template.php
2.Find the “function comments_template( $file = ‘/comments.php’ ){“
3.Inside the function you will see :
if ( ! (is_single() || is_page() || $withcomments) )
return;
Change this to
if ( ! (is_single() || is_page() || $withcomments) )
//return;
4.Open /wp-content/themes/yourtheme/index.php
add “<?php comments_template(); ?>” inside post loop
“while (have_posts()) : the_post(); “This displays comments under each post on the homepage but also shows the comment form 10 times, once with each post.
My workaround has been to add an extra function to the comment_template.php file called partcomments_template which instead of linking to comments.php, links to partcomments.php. The file partcomments.php is identical to comments.php but without the form section.Instead of all this would it be possible to put a conditional in the comments.php file which only displays the form part of it if the user is viewing a single post?
- The topic ‘Display comments but not comments form on homepage’ is closed to new replies.