我为自定义评论表单提供了以下代码:
<?php $fields = array(
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author"><input id="author" name="author" type="text" value="" placeholder="*Please enter your name..." aria-required="true" /></p>',
'email' =>
'<p class="comment-form-email"><input id="email" name="email" type="text" value="" placeholder="*Please enter your email..." aria-required="true" /></p>',
'comment_field' =>
'<p class="comment-form-comment"><textarea id="comment" placeholder="*Please type your message here..." name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
)),
'comment_notes_after' => '',
); ?>
<div class="comments-form"><?php comment_form($fields); ?></div>
然而,textarea显示两次,默认的一个带有标签而我的自定义没有(见截图:http://i.imgur.com/SHM0jzi.png)。如何摆脱默认的?
答案 0 :(得分:3)
现在已经解决了。 comment_field不应该在'fields'数组中,因为它是comment_form()函数的一个独特参数。所以,它应该是:
<?php $fields = array(
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' =>
'<p class="comment-form-author"><input id="author" name="author" type="text" value="" placeholder="*Please enter your name..." aria-required="true" /></p>',
'email' =>
'<p class="comment-form-email"><input id="email" name="email" type="text" value="" placeholder="*Please enter your email..." aria-required="true" /></p>',
)),
'comment_field' =>
'<p class="comment-form-comment"><textarea id="comment" placeholder="*Please type your message here..." name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
'comment_notes_after' => '',
); ?>
答案 1 :(得分:0)
很好的答案,它帮助了我。这是我的解决方案:
$fields = array(
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label><br /> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="author" name="author" type="text" size="30"' . $aria_req . ' /></p>',
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label><br /> ' . ( $req ? '<span class="required">*</span>' : '' ) .
'<input id="email" name="email" type="text" size="30"' . $aria_req . ' /></p>',
);
$comments_args = array(
'fields' => $fields,
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <br /> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>',
);
comment_form($comments_args);
我知道这是一个3岁的问题,但这是我对这个问题得到的极少数结果之一,所以我想回复它以防万一。