函数文档

comment_id_fields()

💡 云策文档标注

概述

comment_id_fields() 函数用于在评论表单中输出隐藏的 HTML 输入字段,以支持嵌套评论回复功能。它必须在 comments.php 模板的 <form> 部分内调用。

关键要点

  • 输出隐藏的 input 元素,包含 comment_post_ID 和 comment_parent 值,用于标识评论帖子和父评论。
  • 参数 $post 可选,可以是整数、WP_Post 对象或 null,默认为当前全局帖子。
  • 此函数是 get_comment_id_fields() 的包装器,直接输出 HTML。
  • 从 WordPress 6.2.0 版本起,参数从 $post_id 重命名为 $post,并增加了 WP_Post 支持。

注意事项

  • 必须放置在 comments.php 模板的 <form> 标签内,以确保表单正常工作。
  • 如果未提供 $post 参数,函数将自动使用当前全局帖子。

📄 原文内容

Outputs hidden input HTML for replying to comments.

Description

Adds two hidden inputs to the comment form to identify the comment_post_ID and comment_parent values for threaded comments.

This tag must be within the <form> section of the comments.php template.

See also

Parameters

$postint|WP_Post|nulloptional
The post the comment is being displayed for.
Defaults to the current global post.

Default:null

Source

function comment_id_fields( $post = null ) {
	echo get_comment_id_fields( $post );
}

Changelog

Version Description
6.2.0 Renamed $post_id to $post and added WP_Post support.
2.7.0 Introduced.