在 WordPress 主页上显示评论
我已将以下代码插入到模板循环中(在正确的位置),但它没有输出任何注释。为什么?
<?php
$withcomments = true; // force comments form and comments to show on front page
comments_template( '', true );
?>
我正在尝试在帖子的主页流上显示每个帖子的评论。
我正在使用 二十十 主题。
I've inserted the following code to the template loop (in the correct place), but it is not outputting any comments. Why?
<?php
$withcomments = true; // force comments form and comments to show on front page
comments_template( '', true );
?>
I'm trying to display comments for each post on the main-home-page stream of posts.
I'm using the Twenty Ten theme.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在
:
Try this before the
<?php endwhile; ?>
of the loop in loop.php:试试这个:
Try this:
有一种更简单的方法,不需要编辑 PHP 代码。首先确保您可以在其他页面上创建评论,如果有效,请返回主页。
单击右上角的齿轮图标以显示设置,然后在设置底部附近将“页面属性”“模板”从“首页模板”更改为“默认模板”。保存即可有意见。
但是,您可能会失去主页的其他功能(您可以随时将模板改回来)。对于我来说,我没有失去任何东西。
了解普通的 WordPress 博客旨在在博客(帖子)上发表评论,而不是在主页上发表评论。默认情况下,您甚至不应该在任何页面上发表评论(只是帖子),但这很容易启用。这就是为什么通常不允许发表任何评论,但如果您有一个单页网站,这就是一个问题。
另请注意,有许多不同的主题,有些允许在主页上发表评论。
There is a much simpler way that doesn't involve editing PHP code. First make sure you can create comments on other pages and if that is working, go back to the home page.
On the top right, click the gear icon to show settings and near the bottom of settings change the "page attributes" "template" from "front page template" to "default template". Save and you will have comments.
However, you may lose other features of the home page (you can always change the template back). For me I didn't lose anything.
Understand that a normal WordPress blog is intended to have comments on the blogs (posts), but not on the home page. By default you shouldn't even have comments on any pages (just posts), but that is easily enabled. That is why normally there aren't any comments allowed, but if you have a one-page site this is a problem.
Also note that there are many different themes and some do allow comments on the home page.