comment_form()

显示发布评论的对话框

描述

此标记输出一个完整的注释表单,以便在模板中使用。

大多数字符串和表单字段可以通过传递到函数中的$args数组进行控制,而如果您只想添加新字段或删除单个字段,也可以选择使用 comment_form_default_fields 过滤器来修改默认字段数组。所有字段也单独通过表单 comment_form_field_$name 过滤器传递,其中 $name 是字段数组中使用的键。

请注意,尽管大多数参数都标记为可选,但不将它们全部包含在代码中会在使用 define('WP_DEBUG', true); 时产生错误

用法

默认用法

<?php comment_form(); ?>

正如在流行的二十个主题中看到的 – 在这里称为: wp-content/themes/twentyten/comments.php

参数

args

(array) (可选) 表单中的字符串、字段等选项。

默认值: (See below)

post_id

(mixed) (可选) 要为其生成表单的帖子 ID,如果为 null,则使用当前帖子

默认值:空(当前帖子)

$args

注意:如果使用 $new_defaults 更改注释模板中的$defaults,则必须在调用 comment_form($new_defaults); 之前声明 $new_defaults,否则它们不会生效。

 默认值:

fields

(array) (可选)输入字段:“作者”、“电子邮件”、“网址”。

默认值: apply_filters( 'comment_form_default_fields', $fields )

comment_field

(string) (可选) 注释正文的文本区域和标签。

默认值:

/* ———————————-
* wordpress函数 星空站长网  收集
* ———————————- */

‘<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  must_log_in

(string) (可选)

默认值:

/* ———————————-
* wordpress函数 Xingkongweb.com收集
* ———————————- */

‘<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) (可选)

默认值:

/* ———————————-
* wordpress函数 XingkongWeb.com收集
* ———————————- */

‘<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) (可选) 如果用户未登录,则在注释表单字段集之前显示的文本或 HTML。

默认值:

/* ———————————-
* wordpress函数 星空站长网 收集
* ———————————- */

‘<p class=”comment-notes”>’ . __( ‘Your email address will not be published.’ ) . ( $req ? $required_text : ” ) . ‘</p>’

comment_notes_after  comment_notes_after

(string) (可选) 要在一组注释字段之后(提交按钮之前)显示的文本或 HTML。

默认值:

‘<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) (可选) 元素( <form> 标签) id 的属性 form 值。

默认值: ‘commentform’

id_submit  id_submit

(string) (可选) 提交按钮 id 的属性值。

默认值: ‘submit’

class_submit  class_submit

(string) (可选)提交按钮 class 的属性值。

默认值: ‘submit’

title_reply  title_reply

(string) (可选) 注释表单的标题(不回复注释时,请参阅comment_form_title)。

默认值: __( ‘Leave a Reply’ )

title_reply_to  title_reply_to

(string) (可选) 注释窗体的标题(回复注释时,请参阅comment_form_title)。

默认值: __( ‘Leave a Reply to %s’ )
默认值: __( ‘回复 %s’ )

cancel_reply_link  cancel_reply_link

(string) (可选) 链接标签以取消回复。

默认值: __( ‘Cancel reply’ )

label_submit  label_submit

(string) (可选)提交按钮的名称。

默认值: __( ‘Post Comment’ )

$fields

Default form fields:  默认表单域:

$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>’,

);

注意:要在自定义回调函数中使用上述代码中存在的变量,您必须首先使用以下方法在回调中设置这些变量:

$commenter = wp_get_current_commenter();

$req = get_option( ‘require_name_email’ );

$aria_req = ( $req ? ” aria-required=’true’” : ” );

默认$args数组

$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 ),

);

示例

如何更改某些注释表单字段的简单示例。

$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()

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索