这个comment_form()
函数是可定制的,它接受各种参数。看看这些示例参数,您可以修改它们以满足您的需要:
$fields = array(
\'author\' =>
\'<input name="author" type="text" value="\' . esc_attr( $commenter[\'comment_author\'] ) .\'" size="30" placeholder="\'.__(\'Your name\',\'text-domain\').( $req ? \' (Required)\' : \'\' ).\'"/>\',
\'email\' =>
\'<input name="email" type="text" value="\' . esc_attr( $commenter[\'comment_author_email\'] ) .\'" size="30" placeholder="\'.__(\'Your email\',\'text-domain\').( $req ? \' (Required)\' : \'\' ).\'"/>\',
);
$args = array(
\'id_form\' => \'commentform\',
\'class_form\' => \'comment-form\',
\'id_submit\' => \'submit\',
\'class_submit\' => \'submit\',
\'name_submit\' => \'submit\',
\'submit_button\' => \'<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />\',
\'title_reply\' => \'\',
\'title_reply_to\' => __( \'Reply to %s\',\'text-domain\' ),
\'cancel_reply_link\' => __( \'Cancel comment\',\'text-domain\' ),
\'label_submit\' => __( \'Post comment\',\'text-domain\' ),
\'format\' => \'xhtml\',
\'comment_field\' => \'<textarea id="comment" name="comment" placeholder="\'.__(\'Comment text\',\'text-domain\').\'" cols="45" rows="8" aria-required="true">\' .\'</textarea>\',
\'logged_in_as\' => \'<p class="logged-in-as">\' .
sprintf(
__( \'Logged in as %1$s. <a href="%2$s" title="%3$s">%4$s</a>\', \'text-domain\'),
$user_identity,
wp_logout_url( apply_filters( \'the_permalink\', get_permalink( ) ) ),
__(\'Log out?\',\'text-domain\'),
__(\'Click to log out.\',\'text-domain\')
) . \'</p>\',
\'comment_notes_before\' => \'<p class="comment-notes">\' . __( \'Your email address will not be published.\',\'text-domain\' ) .\'</p>\',
\'fields\' => apply_filters( \'comment_form_default_fields\', $fields ),
);
comment_form( $args );
您可以将任何类添加到元素中,或将它们包装到
<div>
或
<p>
.
如果要将文本区域移动到其他字段下方,可以使用comment_form_fields
过滤器:
function move_comment_field_to_bottom( $fields ) {
$comment_field = $fields[\'comment\'];
unset( $fields[\'comment\'] );
$fields[\'comment\'] = $comment_field;
return $fields;
}
add_filter( \'comment_form_fields\', \'move_comment_field_to_bottom\' );
更新以在
content.php
文件中保存第一个代码
comment.php
, 然后以这种方式调用循环中的表单:
if ( comments_open() || \'0\' != get_comments_number() ) {
comments_template();
}
这将附加
comment.php
到您的内容。