Display a Wordpress Comment Template Outside of a Loop

So, I am creating a wordpress theme, and I need the comments to be displayed in the drop-down list from each post on the main page. Bullshit you must click on the message to see the comments! It worked very well when there was only one post. It worked with only one post because I was displaying the OUTSIDE loop comment template. But with several messages, the comment template should be inside the loop, however, when you put the link of the comment template in the loop, it does not work, that is, the template does not appear!

How can I get a comment template to display in a loop so that it appears in every message on the main page, and I can configure it as a drop-down menu?

Here is the site on which I am implementing it: http://thenozzle.net/ You can see this, or rather, not see what happens if you click "Show # Comments Here". Simple PHP material, but I canโ€™t understand why, when the comment template link is palce din th eloop, it doesnโ€™t work.

Here is the link and code:

<div id="dropdowncomments"> <?php comments_template(); ?> </div> 

As I said, the dropdown comments are hidden, and when you click on it, it appears, but the comment template does not load inside loop.php, so nothing good.

Any help?

+6
source share
1 answer

Itโ€™s easy (I hope I understand you correctly). Immediately after calling the_content() set the $withcomments (global) variable and call comments_template() :

 the_content(); global $withcomments; $withcomments = 1; comments_template( 'comments.php', true ); 
+10
source

Source: https://habr.com/ru/post/890750/


All Articles