天天看點

如何在WordPress主題的首頁上顯示評論

Recently while working on a very secret project, we found a need to show comments on the homepage of the site. Normally, on single pages you can just call comments_template(); and it should display, but it wasn’t showing up. All we ended up getting was a blank div container. After doing a quick search online, we were able to find the answer. In this article, we will show you how to show comments on the homepage of your WordPress site.

最近,在進行一個非常秘密的項目時,我們發現有必要在網站首頁上顯示評論。 通常,在單個頁面上,您可以隻調用comment_template();。 并且應該顯示,但是沒有顯示。 我們最終得到的隻是一個空白的div容器。 線上快速搜尋後,我們找到了答案。 在本文中,我們将向您展示如何在WordPress網站的首頁上顯示評論。

Inside the loop right before endwhile, simply add the following code:

在結束之前在循環内,隻需添加以下代碼:

<?php 
$withcomments = "1";
comments_template(); // Get wp-comments.php template ?>           

A single line $withcomments makes all the difference.

一行$ withcomments改變了一切。

Note: this was a very simple one page site we threw up. So the theme elements were style.css, index.php, and comments.php file. We were calling a loop to display a specific page on the index.php file along with other things.

注意:這是我們建立的非常簡單的一頁網站。 是以主題元素是style.css,index.php和comments.php檔案。 我們正在調用一個循環,以在index.php檔案上顯示特定頁面以及其他内容。

We hope that this would help some of you. Some of you may even have a better way of doing this. If you do, please share it with us in the comments.

希望對您有所幫助。 你們當中有些人甚至可能有更好的方法。 如果您這樣做,請在評論中與我們分享。

翻譯自: https://www.wpbeginner.com/wp-themes/how-to-show-comments-on-the-homepage-of-your-wordpress-theme/