简体   繁体   English

如何在wordpress的主页上添加评论?

[英]How to add comments on home page in wordpress?

I want to add a comments section in index.php of Wordpress.我想在 Wordpress 的index.php中添加一个评论部分。

I added the following code:我添加了以下代码:

<td align="left" valign="top">
    <?php $withcomments = 1;comments_template(); ?>
</td>

Comments are shown because of the above code, but when a user adds a comment on the index page, it redirects to a default post and also adds that comment to that default post.由于上述代码显示评论,但是当用户在索引页面上添加评论时,它会重定向到默认帖子并将该评论添加到该默认帖子。

Is it possible to make comments on the index page and also have them shown in the index page?是否可以在索引页上发表评论并将它们显示在索引页中? If anyone can help me it will be appreciated.如果有人可以帮助我,将不胜感激。

Comments can be enabled on pages and / or posts .可以在pages和/或posts上启用评论。

If your wordpress front page displays a static page you can enable comments on it.如果你的 wordpress 首页显示一个static page你可以在它上面启用评论。

If it happens to display "Your latest posts," it's simply a list of some recent posts (formatted according to your theme).如果它恰好显示“您的最新帖子”,它只是一些最近帖子的列表(根据您的主题格式化)。 There's no single item, post or page, there to accept comments.没有单个项目、帖子或页面可以接受评论。

You can find out how this is set up for your WordPress installation by looking at Settings / Reading on your dashboard.您可以通过查看仪表板上的设置/阅读来了解如何为您的 WordPress 安装进行设置。

It depends a lot about how your theme is structured: loop is written in single.php file directly, or there is a loop file which is included in both single.php and index.php .这在很大程度上取决于您的主题的结构:循环直接写入 single.php 文件,或者有一个包含在 single.php 和 index.php 中的循环文件。

Your homepage should be either home.php or index.php ( usually the second version ).您的主页应该是 home.php 或 index.php(通常是第二个版本)。 If the loop is shared for both single post and index, you should find something like this:如果循环为单个帖子和索引共享,您应该会发现如下内容:

<?php // Load Comments template (on single post pages, and "Page" pages, if set on options page)
        if ( is_single() OR ( is_page() && $bfa_ata_comments_on_pages == "Yes") ) {
            if (function_exists('paged_comments')) {
                paged_comments_template(); // If plugin "Paged Comments" is activated, for WP 2.6 and older
                } else {
                comments_template(); // This will load either legacy comments template (for WP 2.6 and older) or the new standard comments template (for WP 2.7 and newer)
            }
        } ?>

and replace it with something like this:并用这样的东西替换它:

<?php // Load Comments template (on single post pages, and "Page" pages, if set on options page)
if ( is_single() OR ( is_page() && $bfa_ata_comments_on_pages == "Yes" && !is_front_page() )) {
if (function_exists('paged_comments')) {
paged_comments_template(); // If plugin "Paged Comments" is activated, for WP 2.6 and older
} else {
comments_template(); // This will load either legacy comments template (for WP 2.6 and older) or the new standard comments template (for WP 2.7 and newer)
}
} ?>

If your single loop is different from your homepage loop, then you should copy the code that post the comment form from the single loop into the index loop.如果您的单循环与主页循环不同,那么您应该将发布评论表单的代码从单循环复制到索引循环中。

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

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