In my single PHP template, both the comments and the comments entry form appear at the bottom of the post (without clicking anything). For this I use:
<?php comments_number(‘0’, ‘1’, ‘%’); ?>
<?php comments_template(); // Get wp-comments.php template ?>
In my index and archive templates, I also would like it to work the same way. I can’t get it to work, though. I read in the docs that <?php comments_template(); ?> is “for use in single post and page displays.” OK, so then I need a template tag for index and archive pages.
Unfortunately the only template tag I have found is <?php comments_popup_link(‘0’, ‘1’, ‘%’); ?>. But this template tag has a very different behaviour. It doesn’t immediately show the comments and comment form. Rather, it gives a hyperlink. And the hyperlink calls the single.php template. The result is that the user must wait for the whole page to load, and then the cursor is positioned at the top of the page. So the user may not notice that the comments and comment form appeared at the bottom of the page. I don’t want to do it this way.
Is there an alternative out there that behaves like <?php comments_template(); ?> but works in index.php and archive.php?
if you look into the first lines of the code of comments_template()
(function starts in /wp-includes/comment-template.php line 830 ++) you will find an if statement that restricts the code to single pages and posts, unless the global variable $withcomments is set to true or 1;