简体   繁体   English

在'循环'之外显示Wordpress'评论模板'

[英]Displaying the Wordpress 'Comments Template' outside the 'loop'

So I'm building a wordpress theme, and I need the comments to come down in a dropdown from each post on the homepage. 所以我正在构建一个wordpress主题,我需要在主页上的每个帖子的下拉列表中记下这些评论。 Bullshit you have to click on the post to see the comments! 废话你必须点击帖子才能看到评论! It worked really well, when there was only one post. 当只有一个帖子时,它工作得非常好。 It worked with only one post because I was displaying the comments template OUTSIDE the loop. 它只使用了一个帖子,因为我在循环中显示注释模板。 But with multiple posts, the comments template must be inside the loop, however, when you put the comments template reference in the loop it doesn't fire, meaning the template isn't displayed! 但是对于多个帖子,注释模板必须在循环内部,但是,当您将注释模板引用放在循环中时它不会触发,这意味着模板不会显示!

How can I get the comments template to display in the loop so it will appear on each post on the homepage and I can set it up as a dropdown menu? 如何让循环中显示的评论模板显示在主页的每个帖子上,我可以将其设置为下拉菜单?

Here's the site I'm implementing it on: http://thenozzle.net/ You can see it, or rather, not see it happening if you click on 'Show # Comments Here'. 这是我正在实施它的网站: http//thenozzle.net/你可以看到它,或者更确切地说,如果你点击'Show#Comments Here'就看不到它。 Simple php stuff, but I can't figure out why when the comments template reference is palce din th eloop, is doesn't fire. 简单的PHP的东西,但我无法弄清楚为什么当评论模板参考是palce din th eloop时,是不会开火。

Here's the reference and code: 这是参考和代码:

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

Like I said, dropdown comments is hidden, and when you click on it, it appears, but comments template isn't loading inside loop.php so, no good. 就像我说的那样,下拉注释是隐藏的,当你点击它时,它会出现,但是注释模板没有加载到loop.php里面,所以没有好处。

Any help? 有帮助吗?

It is easy (I hope I understood you correctly). 这很容易(我希望我理解正确)。 Just after the the_content() call, setup the $withcomments variable (global) and call comments_template() : the_content()调用之后,设置$withcomments变量(全局)并调用comments_template()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM