WordPress函数文档comment_form()
显示发布评论的对话框 描述 This tag outputs a complete commenting fo…
显示发布评论的对话框
描述
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 comment_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 comment_form_field_$name
where $name
is the key used in the array of fields.
Please note, that although most parameters are marked as optional, not including them all in your code will produce errors when using define('WP_DEBUG', true);
用法
<?php comment_form( $args, $post_id ); ?>
Default Usage
<?php comment_form(); ?>
As seen in the popular twentyten theme – called here: wp-content/themes/twentyten/comments.php
参数
args
(array) (可选) Options for strings, fields etc in the form.
默认值: (See below)
post_id
(mixed) (可选) Post ID to generate the form for, uses the current post if null
默认值: null (the current post)
$args
Note: If you change the $defaults in your comments template using $new_defaults, you must declare the $new_defaults BEFORE you call comment_form($new_defaults);
, otherwise, they won’t take effect.
Default values:
fields
(array) (可选) Input fields: ‘author’, ’email’, ‘url’.
默认值: apply_filters( 'comment_form_default_fields', $fields )
comment_field
(string) (可选) The textarea and the label of comment body.
默认值:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
‘<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
(string) (可选)
默认值:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
‘<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( ) ) ) ) . ‘</p>’
|
logged_in_as
(string) (可选)
默认值:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
‘<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( ) ) ) ) . ‘</p>’
|
comment_notes_before
(string) (可选) Text or HTML to be displayed before the set of comment form fields if the user is not logged in.
默认值:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
‘<p class=”comment-notes”>’ . __( ‘Your email address will not be published.’ ) . ( $req ? $required_text : ” ) . ‘</p>’
|
comment_notes_after
(string) (可选) Text or HTML to be displayed after the set of comment fields (and before the submit button)
默认值:
1
2
3
4
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
‘<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
(string) (可选) value of the id
attribute of form
element (<form>
tag).
默认值: ‘commentform’
id_submit
(string) (可选) value of the id
attribute of submit button.
默认值: ‘submit’
class_submit
(string) (可选) value of the class
attribute of submit button.
默认值: ‘submit’
title_reply
(string) (可选) The title of comment form (when not replying to a comment, see comment_form_title).
默认值: __( ‘Leave a Reply’ )
title_reply_to
(string) (可选) The title of comment form (when replying to a comment, see comment_form_title).
默认值: __( ‘Leave a Reply to %s’ )
cancel_reply_link
(string) (可选) link label to cancel reply.
默认值: __( ‘Cancel reply’ )
label_submit
(string) (可选) the name of submit button.
默认值: __( ‘Post Comment’ )
$fields
Default form fields:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
$fields = array(
‘author’ =>
‘<p class=”comment-form-author”><label for=”author”>’ . __( ‘Name’, ‘domainreference’ ) . ‘</label> ‘ .
( $req ? ‘<span class=”required”>*</span>’ : ” ) .
‘<input 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”>’ . __( ‘Email’, ‘domainreference’ ) . ‘</label> ‘ .
( $req ? ‘<span class=”required”>*</span>’ : ” ) .
‘<input 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”>’ . __( ‘Website’, ‘domainreference’ ) . ‘</label>’ .
‘<input id=”url” name=”url” type=”text” value=”‘ . esc_attr( $commenter[‘comment_author_url’] ) .
‘” size=”30″ /></p>’,
);
|
Note: To use the variables present in the above code in a custom callback function, you must first set these variables within your callback using:
1
2
3
4
5
6
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
$commenter = wp_get_current_commenter();
$req = get_option( ‘require_name_email’ );
$aria_req = ( $req ? ” aria-required=’true’” : ” );
|
Default $args array
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
$args = array(
‘id_form’ => ‘commentform’,
‘id_submit’ => ‘submit’,
‘class_submit’ => ‘submit’,
‘name_submit’ => ‘submit’,
‘title_reply’ => __( ‘Leave a Reply’ ),
‘title_reply_to’ => __( ‘Leave a Reply to %s’ ),
‘cancel_reply_link’ => __( ‘Cancel Reply’ ),
‘label_submit’ => __( ‘Post Comment’ ),
‘format’ => ‘xhtml’,
‘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() ) )
) . ‘</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( ) ) )
) . ‘</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>’,
‘fields’ => apply_filters( ‘comment_form_default_fields’, $fields ),
);
|
示例
Simple example how to change some comment form fields.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
$comments_args = array(
// change the title of send button
‘label_submit’=>‘Send’,
// change the title of the reply section
‘title_reply’=>‘Write a Reply or Comment’,
// remove “Text or HTML to be displayed after the set of comment fields”
‘comment_notes_after’ => ”,
// redefine your own textarea (the comment body)
‘comment_field’ => ‘<p class=”comment-form-comment”><label for=”comment”>’ . _x( ‘Comment’, ‘noun’ ) . ‘</label><br /><textarea id=”comment” name=”comment” aria-required=”true”></textarea></p>’,
);
comment_form($comments_args);
|
相关
comments_template()
Comments Function(函数)s
- Function(函数): cancel_comment_reply_link()
- Function(函数): comment_author()
- Function(函数): comment_author_email()
- Function(函数): comment_author_email_link()
- Function(函数): comment_author_IP()
- Function(函数): comment_author_link()
- Function(函数): comment_author_rss()
- Function(函数): comment_author_url()
- Function(函数): comment_author_url_link()
- Function(函数): comment_class()
- Function(函数): comment_date()
- Function(函数): comment_excerpt()
- Function(函数): comment_form_title()
- Function(函数): comment_form(),
- Function(函数): comment_ID()
- Function(函数): comment_id_fields()
- Function(函数): comment_reply_link()
- Function(函数): comment_text()
- Function(函数): comment_text_rss()
- Function(函数): comment_time()
- Function(函数): comment_type()
- Function(函数): comments_link
- Function(函数): comments_number()
- Function(函数): comments_open(),
- Function(函数): comments_popup_link()
- Function(函数): comments_popup_script()
- Function(函数): comments_rss_link()
- Function(函数): get_avatar()
- Function(函数): next_comments_link()
- Function(函数): paginate_comments_links()
- Function(函数): permalink_comments_rss()
- Function(函数): previous_comments_link()
- Function(函数): wp_list_comments()
- 原文:http://codex.wordpress.org/Function_Reference/comment_form
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!