0

我有以下代码用于自定义评论表单:

<?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)。我怎样才能摆脱默认的?

4

2 回答 2

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' => '',

); ?>   
于 2013-10-03T14:28:42.577 回答
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 年前的问题,但这是我在这个问题上获得的极少数结果之一,所以我想我会回复它,以防它帮助其他人。

于 2016-09-20T10:56:22.093 回答