模板層次結構
https://developer.wordpress.org/themes/basics/template-hierarchy/
官方參考文檔:
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comments/
評論表輸入:
comment_form
https://codex.wordpress.org/Function_Reference/comment_form
自定義評論列表:
wp_list_comments
https://codex.wordpress.org/Function_Reference/wp_list_comments
根據各種參數顯示帖子或頁面的所有注釋,包括管理區域中設置的參數。
wp_list_comments 函數是一個循環輸出當前文章或頁面每個評論的函數
comment_reply_link
https://developer.wordpress.org/reference/functions/comment_reply_link/
回復評論的文本
https://developer.wordpress.org/reference/functions/comment_reply_link/?updated-note=3039#comment-3039
WP大學:
https://www.wpdaxue.com/wordpress-comment_form.html
首先,看下我制作的初始效果:

沒有編寫相關代碼時,采用默認的結構。
我編寫的相關代碼如下:
主要是兩個文件,一個是 comments.php 提供評論模板(主題根目錄內)
為了自定義部分內容,我們還有 comment-custom.php(在inc文件夾內)
上面的代碼
可以在 functions.php 中如下引用 comment-custom.php 文件:
// 添加自定義評論模板
require_once get_template_directory() .'/inc/comment-custom.php';
自定義評論輸入信息表單:

在functions.php 添加下列代碼:
// 提交表單
function my_fields($fields) {
??$fields = array(
??????'cookies' =>
??????'<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
??????'<label for="wp-comment-cookies-consent">' . __( '下次評論時, 請在此瀏覽器中保存我的姓名、電子郵件和網站。' ) . '</label></p>',
'author' =>
???????? '<p class="comment-form-author"><label for="author">' . __( '您的姓名* ', 'xitou' ) .'</label>' .
???????? '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) .
???????? '" size="30"' . $aria_req . ' /></p>',
????????'email' =>
???????? '<p class="comment-form-email"><label for="email">' . __( '您的郵件* ', 'xitou' ) .'</label>' .
???????? '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) .
???????? '" size="30"' . $aria_req . ' /></p>',
??????
????????'url' =>
???????? '<p class="comment-form-url"><label for="url">' . __( '您的站點 ', 'zero' ) . '</label>' .
???????? '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) .
???????? '" size="30" /></p>',
);
??return $fields;
}
add_filter('comment_form_default_fields','my_fields');
如自定義評論輸入框:

在comments.php 相關位置添加以下代碼;
$comments_args = array(
????????'label_submit' => __( '發表評論', 'textdomain' ),
'title_reply' => __( '', 'textdomain' ), // 評論框下方文本
????????'comment_notes_before'=>'',//電子郵件地址不會被公開,必填項已用*標注
????????'title_reply_to' => __( '給 %s留下評論' ),
????????'cancel_reply_link' => __( '取消評論' ),
????????'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( '發表評論', 'noun' ) . '</label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>',
);
comment_form( $comments_args );
完