comment_time()
云策文档标注
概述
comment_time() 函数用于显示当前评论的时间,基于 WordPress 的评论系统。它接受可选参数来指定时间格式和评论 ID,默认使用当前评论。
关键要点
- 函数功能:输出当前评论的时间,基于 get_comment_time() 实现。
- 参数:$format(可选,PHP 时间格式,默认为 'time_format' 选项)和 $comment_id(可选,评论 ID 或 WP_Comment 对象,默认为当前评论)。
- 版本变化:WordPress 6.2.0 版本添加了 $comment_id 参数。
- 相关函数:get_comment_time() 用于检索评论时间。
代码示例
comment_time('H:i:s'); // 显示当前评论时间,格式为“22:04:11”注意事项
时间格式应遵循 PHP 的 date() 函数规范,可参考 WordPress 的日期和时间格式化文档。
原文内容
Displays the comment time of the current comment.
Parameters
$formatstringoptional-
PHP time format. Defaults to the
'time_format'option. $comment_idint|WP_Commentoptional-
WP_Comment or ID of the comment for which to print the time.
Default current comment.
Source
function comment_time( $format = '', $comment_id = 0 ) {
echo get_comment_time( $format, false, true, $comment_id );
}
Skip to note 2 content
Codex
Basic Example
Displays the current comment time in the format “22:04:11”.
<p>comment timestamp: </p>