comment_formタグは、テンプレート内で使用するための完全なコメントフォームを出力します。
あなただけの新しいものを追加したり1つのフィールドを削除したい場合、デフォルトのフィールドの配列を変更するためのcomments_form_default_fieldsフィルターを使用するための選択するのと同時に、ほとんどの文字列とフォームフィールドは、関数に引き渡される$args配列に制御される可能性があります。
すべてのフィールドは個別の形式のフィルタを介して渡されるcomments_form_field_$nameの$nameがキーフィールドの配列で使用されます。
This tag outputs a complete commenting form for use within a template.
Most strings and form fields may be controlled through the $args array passed into the function, while you may also choose to use the comments_form_default_fields filter to modify the array of default fields if you’d just like to add a new one or remove a single field. All fields are also individually passed through a filter of the form comments_form_field_$name where $name is the key used in the array of fields.
comment_formのテンプレートタグ使用方法
<?php comment_form($args, $post_id); ?>
comment_formのパラメーター
args
(array) (required) 文字列のオプションは、フォーム内のフィールド等です。下記の詳細をご覧ください。
(array) (required) Options for strings, fields etc in the form. See below for more detail.
Default: None
post_id
(mixed) (required) nullの場合、現在の投稿を使用するフォームを生成する記事IDです。
(mixed) (required) Post ID to generate the form for, uses the current post if null
Default: None
$args
Default value:
<?php $defaults = array( 'fields' => apply_filters( 'comment_form_default_fields', array( 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />' . '</p><!-- #form-section-author .form-section -->', 'email' => '<p class="comment-form-email">' . '<label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) . '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />' . '</p><!-- #form-section-email .form-section -->', 'url'=> '<p class="comment-form-url">' . '<label for="url">' . __( 'Website' ) . '</label>' . '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />' . '</p><!-- #form-section-url .form-section -->' ) ), 'comment_field' => '<p class="comment-form-comment">' . '<label for="comment">' . __( 'Comment' ) . '</label>' . '<textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>' . '</p><!-- #form-section-comment .form-section -->', '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="%s">%s</a>.<a href="%s" title="Log out of this account">Log out?</a></p>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ), 'comment_<h2>注釈</h2>_before' => '<p class="comment-<h2>注釈</h2>">' . __( 'Your email is<em>never</em> published nor shared.' ) . ( $req ? __( ' Required fields are marked<span class="required">*</span>' ) : '' ) . '</p>', 'comment_<h2>注釈</h2>_after' => '<dl class="form-allowed-tags"><dt>' . __( 'You may use these<abbr title="HyperText Markup Language">HTML</abbr> tags and attributes:' ) . '</dt><dd><code>' . allowed_tags() . '</code></dd></dl>', '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' ), ); ?>
author
(string) (optional)
Default:
(string) (optional)
Default:
url
(string) (optional)
Default:
comment_field
(string) (optional)
Default:
must_log_in
(string) (optional)
Default:
logged_in_as
(string) (optional)
Default:
comment_notes_before
(string) (optional)
Default:
comment_notes_after
(string) (optional)
Default:
id_form
(string) (optional)
Default:
id_submit
(string) (optional)
Default:
id_submit
(string) (optional)
Default: ‘submit’
title_reply
(string) (optional)
Default: __( ‘Leave a Reply’ )
title_reply_to
(string) (optional)
Default: __( ‘Leave a Reply to %s’ )
cancel_reply_link
(string) (optional)
Default: __( ‘Cancel reply’ )
label_submit
(string) (optional)
Default: __( ‘Post Comment’ )
Return
void
例
デフォルトの使い方
<?php comment_form(); ?>
Twenty Tenteテーマ
wp-content/themes/twentyten/comments.phpを見てください。
変更ログ
- 3.0.0 : New template tag.
ソースファイル
comment_form()はwp-includes/comment-template.php内に位置しています。
comment_form() is located in wp-includes/comment-template.php.
関連テンプレートタグ
comments_number, comments_link, comments_rss_link, comments_popup_script, comments_popup_link, comment_ID, comment_author, comment_author_IP, comment_author_email, comment_author_url, comment_author_email_link, comment_author_url_link, comment_author_link, comment_type, comment_text, comment_excerpt, comment_date, comment_time, comment_author_rss, comment_text_rss, permalink_comments_rss, wp_list_comments, comment_reply_link, cancel_comment_reply_link, comment_form_title, comment_id_fields, previous_comments_link, next_comments_link, paginate_comments_links