自定义注释字段在Wordpress中不起作用

时间:2016-02-04 15:21:40

标签: wordpress forms comments

我使用comment_form()修改了我的评论表单:

$comments_form_args = array(
    'fields' => apply_filters('comment_form_default_fields', array(
        'author' =>
                '<div class="form-group">' .
                '<label for="author" name="author">Name: </label>' .
                    '<input type="text" id="author">' .
                '</div>',
        'email' =>
                '<div class="form-group">' .
                    '<label for="email">E-mail adresse: </label>' .
                    '<input type="email" id="email">' .
                '</div>',
        'url' =>
                '<div class="form-group">' .
                    '<label for="url">WWW: </label>' .
                    '<input type="text" id="url">' .
                '</div>'

    )),
    'comment_field' => '<textarea id="comment" name="comment"></textarea>',
    'class_form' => 'comment',
    'title_reply'=>'Kommentar schreiben',
    'label_submit' => 'Kommentar abschicken',
    'class_submit' => 'pull-right comment-submit',
    'comment_notes_before' => ''

);
comment_form($comments_form_args);

但它无效 - 未添加评论,因为电子邮件和作者字段为空。那是为什么?

1 个答案:

答案 0 :(得分:0)

这应该让你开始:

<?php 

$commenter = wp_get_current_commenter();
$req = get_option( 'require_name_email' );
$aria_req = ( $req ? " aria-required='true'" : '' );
$required_text = sprintf( ' ' . __('Required fields are marked %s','domain'), '<span class="required">*</span>' );
$args = array(
'id_form' => 'commentform',
'id_submit' => 'submit',
'title_reply' => '<br/>' .  esc_html__( 'Leave a Reply', 'domain' ),
'title_reply_to' => '<br/>' . esc_html__( 'Leave a Reply to %s','domain' ),
'cancel_reply_link' =>  esc_html__( 'Cancel Reply', 'domain' ),
'label_submit' =>   esc_html__( 'Post Comment' ,'domain' ),
'comment_field' => '<br/><p class="comment-form-comment"><label for="comment">' . _x( 'Comment post', 'noun', 'domain' ) . '</label><br/><br/><textarea id="comment" name="comment" cols="45" aria-required="true" rows="8"></textarea></p>',
'must_log_in' => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.', 'domain' ), wp_login_url( apply_filters( 'the_permalink', esc_url( get_permalink() ) ) ) ) . '</p>',
'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>','domain' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', esc_url( get_permalink() ) ) ) ) . '</p>',
'comment_notes_before' => '<p class="comment-notes">' .  esc_html__( 'Your email address will not be published.','domain' ) . ( $req ? $required_text : '' ) . '</p>',
'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s', 'domain' ), '<br/><code>' . allowed_tags() . '</code>' ) . '</p>',
'fields' => apply_filters( 'comment_form_default_fields', array(
'author' => '<div class="commnent-text-wrapper"><p class="comment-form-author">' . '<label for="author">' .  esc_html__( 'Name', 'domain' ) . ( $req ? '<span class="required">*</span>' : '' ) . '</label> ' .  '<input class="author" 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">' .  esc_html__( 'Email', 'domain' ). ( $req ? '<span class="required">*</span>' : '' ) . '</label> ' . '<input class="email" 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">' .  esc_html__( 'Website', 'domain' ) . '</label>' . '<input id="url" class="website" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p></div>' ) ) );

 ?>

 <?php comment_form( $args ); ?>
 <ol class="commentlist">
 <?php wp_list_comments(); ?>
 </ol>