模板層次結(jié)構(gòu)
https://developer.wordpress.org/themes/basics/template-hierarchy/
官方參考文檔:
https://developer.wordpress.org/themes/template-files-section/partial-and-miscellaneous-template-files/comments/
評(píng)論表輸入:
comment_form
https://codex.wordpress.org/Function_Reference/comment_form
自定義評(píng)論列表:
wp_list_comments
https://codex.wordpress.org/Function_Reference/wp_list_comments
根據(jù)各種參數(shù)顯示帖子或頁(yè)面的所有注釋?zhuān)ü芾韰^(qū)域中設(shè)置的參數(shù)。
wp_list_comments 函數(shù)是一個(gè)循環(huán)輸出當(dāng)前文章或頁(yè)面每個(gè)評(píng)論的函數(shù)
comment_reply_link
https://developer.wordpress.org/reference/functions/comment_reply_link/
回復(fù)評(píng)論的文本
https://developer.wordpress.org/reference/functions/comment_reply_link/?updated-note=3039#comment-3039
WP大學(xué):
https://www.wpdaxue.com/wordpress-comment_form.html
首先,看下我制作的初始效果:

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

在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">' . __( '下次評(píng)論時(shí), 請(qǐng)?jiān)诖藶g覽器中保存我的姓名、電子郵件和網(wǎng)站。' ) . '</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">' . __( '您的站點(diǎn) ', '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');
如自定義評(píng)論輸入框:

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