comment_form()显示发布评论的对话框

目录

描述

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);

comment_form() 描述

用法

<?php comment_form$args$post_id ); ?>

Default Usage

<?php comment_form(); ?>

twentytendefault6.png

As seen in the popular twentyten theme - called here: wp-content/themes/twentyten/comments.php

comment_form() 用法

参数

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.

默认值:

must_log_in

(string) (可选)

默认值:

logged_in_as

(string) (可选)

默认值:

comment_notes_before

(string) (可选) Text or HTML to be displayed before the set of comment form fields if the user is not logged in.

默认值:

comment_notes_after

(string) (可选) Text or HTML to be displayed after the set of comment fields (and before the submit button)

默认值:

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:

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:

Default $args array

comment_form() 参数

示例

Simple example how to change some comment form fields.

comment_form() 示例

相关