Как сделать свою форму добавления комментария в вордпресс?
Решено
Скажите как можно изменить текст который выводится вокруг формы комментирования в вордпресс? Еще я бы хотел прописать свои классы к форме и добавить пару дивов. Как я понял форма комментариев вордпресс выводится с помощью функции comment_form(). Скажите можно ли заменить эту функции или как то изменить результат ее работы?
1 Ответ(ы)
Ответ
Функция comment_form() принимает ряд параметров которые можно изменить. Именно от значения этих параметров зависит внешний вид формы комментирования.
Вот все аргументы данной функции:
$commenter = wp_get_current_commenter(); $id_user = get_current_user_id(); $user_identity = (!empty($id_user))? get_user_by('id', $id_user)->data->user_login : ''; $fields = array( 'author' => '<div class="form-group"> <label class="sr-only" for="author">Имя</label> <input id="author" name="author" class="form-control" placeholder="Имя" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '"> </div>', 'email' =>'<div class="form-group"> <label class="sr-only" for="email">Email</label> <input id="email" name="email" class="form-control" placeholder="Email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '"> </div>' ); $args = array( 'fields' => apply_filters( 'comment_form_default_fields', $fields ), 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>', 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</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>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', 'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $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' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>', 'id_form' => 'commentform', 'id_submit' => 'submit', 'title_reply' => __( 'Leave a Reply' ), 'title_reply_to' => __( 'Leave a Reply to %s' ), 'cancel_reply_link' => __( 'Cancel reply' ), 'label_submit' => __( 'Post Comment' ), 'class_submit' => 'submit', // Строка. С 4.1. class атрибут для submit элемента. 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', // формат кнопки submit. C 4.2. 'submit_field' => '<p class="form-submit">%1$s %2$s</a>', // формат кнопки submit %1$s - кнопка %2$s - скрытые поля. C 4.2. ); comment_form( $args );