WordPress:Function Reference/get comment

来自站长百科
Xxf3325讨论 | 贡献2008年7月26日 (六) 14:13的版本
跳转至: 导航、​ 搜索

描述

获得评论ID,返回文章的数据库记录。你可以根据$output参数,规定结果的返回方式。

用法

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

例子

得到评论ID为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

    1. 正确的:传递一个需变数作为post_id

$the_comment = & get_comment( $dummy_id = 7 );


    1. 不正确的:literal整数作为post_id

$the_comment = & get_comment( 7 );

// 致命的错误: '只有变数可以为reference传递' or 'Cannot pass parameter 1 by reference' ?>%%%

参数

返回

返回的fields是:

comment_ID
(integer) 评论 ID
comment_post_ID
(integer) 相关文章的ID
comment_author
(string)评论作者名
comment_author_email
(string)评论作者电子邮件
comment_author_url
(string)评论作者网页
comment_author_IP
(string)评论作者IP
comment_date
(string)评论发表的时间(YYYY-MM-DD HH:MM:SS)
comment_date_gmt
(string)评论发表的格林尼治时间(YYYY-MM-DD HH:MM:SS)
comment_content
(string)评论的内容
comment_karma
(integer)评论的karama
comment_approved
(string)评论审核(0, 1 或者 '垃圾广告')
comment_agent
(string)评论的代理器(浏览器,操作系统,等等)
comment_type
(string)如果评论有意义,显示评论的类型(pingback|trackback),如果为一般的评论,为空
comment_parent
(string)上级评论的ID
user_ID
(integer) 如果评论作者注册了,为评论作者的ID (否则为0)

参考

This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.