首页    >    中文手册    >   常用函数-get_comment()

常用函数-get_comment()

常用函数-get_comment()

说明

获取一个评论编号并返回评论所属文章的数据库记录。用户可以通过$output参数指定结果的返回方式。

用法

<?php get_comment($id, $output); ?> 

示例

取得编号为7的评论的作者名称:

<?php
$my_id = 7;
$comment_id_7 = get_comment($my_id); 
$name = $comment_id_7->comment_author;
?> 

也可指定$output参数:

<?php
$my_id = 7;
$comment_id_7 = get_comment($my_id, ARRAY_A);
$name = $comment_id_7['comment_author'];
?> 

<?php
##    Correct: pass a dummy variable as post_id
$the_comment = & get_comment( $dummy_id = 7 );

##    Incorrect: literal integer as post_id
$the_comment = & get_comment( 7 );
//    Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference'
?>

参数

$comment

(整数)(必需)希望获取的评论编号。必须传递一个含有整数的变量(如$id)。单个整数(如:7)将导致严重错误(只有变量能被传递以供参考,或不能传递参数1进行传址)。

默认值:None

$output

(字符串)(必需)结果的显示方式。 OBJECT即作为对象显示,ARRAY_A是作为值的字段名称的关联数组显示,ARRAY_N 则是作为字段值的标量数组显示。

默认值:None

返回的值

返回的字段包括:

comment_ID

(整数)评论编号

comment_post_ID

(整数)相关文章的文章编号

comment_author

(字符串)评论者的名称

comment_author_email

(字符串)评论者的电子邮件

comment_author_url

(字符串)评论者的个人主页

comment_author_IP

(字符串)评论者的IP地址

comment_date

(字符串)评论的日期和时间(年-月-日 时:分:秒)

commetn_date_gmt

(字符串)评论的格林尼治标准时间(年-月-日 时:分:秒)

comment_content

(字符串)评论内容

comment_karma

(整数)评论的karma值

comment_approved

(字符串)评论许可(0,1,或'spam')

comment_agent

(字符串)评论代理(浏览器,操作系统等)

comment_type

(字符串)有意义的评论类型(pingback|trackback),常规评论类型时为空

comment_parent

(字符串)父评论的编号

user_id

(整数)评论者登录后的用户编号(未登录则为0)

参考资料

分类:中文手册

* 版权声明:作者WordPress啦! 转载请注明出处。