WordPress: Function Reference/get comment:修订间差异
来自站长百科
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
== 描述== | == 描述== | ||
获得评论ID,返回文章的数据库记录。你可以根据<tt>$output</tt>参数,规定结果的返回方式。 | 获得评论ID,返回文章的数据库记录。你可以根据<tt>$output</tt>参数,规定结果的返回方式。 | ||
== 用法 == | == 用法 == | ||
%%%<?php get_comment($id, $output); ?> %%% | %%%<?php get_comment($id, $output); ?> %%% | ||
== 例子 == | == 例子 == | ||
得到评论ID为7的作者名: | 得到评论ID为7的作者名: | ||
%%%<?php | %%%<?php | ||
第32行: | 第16行: | ||
$name = $comment_id_7->comment_author; | $name = $comment_id_7->comment_author; | ||
?> %%% | ?> %%% | ||
另外,规定<tt>$output</tt>参数: | 另外,规定<tt>$output</tt>参数: | ||
%%%<?php | %%%<?php | ||
第40行: | 第22行: | ||
$name = $comment_id_7['comment_author']; | $name = $comment_id_7['comment_author']; | ||
?> %%% | ?> %%% | ||
%%%<?php | %%%<?php | ||
## 正确的:传递一个需变数作为post_id | |||
##正确的:传递一个需变数作为post_id | |||
$the_comment = & get_comment( $dummy_id = 7 ); | $the_comment = & get_comment( $dummy_id = 7 ); | ||
##不正确的:literal整数作为post_id | ##不正确的:literal整数作为post_id | ||
$the_comment = & get_comment( 7 ); | $the_comment = & get_comment( 7 ); | ||
// 致命的错误: '只有变数可以为reference传递' or 'Cannot pass parameter 1 by reference' | // 致命的错误: '只有变数可以为reference传递' or 'Cannot pass parameter 1 by reference' | ||
?>%%% | ?>%%% | ||
== 参数 == | == 参数 == | ||
{{Parameter|$comment|integer|你想要获得的评论的ID。'''你必须传递一个包含整数的变数''' (例如 <tt>$id</tt>)。 literal 整数(例如<tt>7</tt>) 会导致严重的错误 (''Only variables can be passed for reference'' or ''Cannot pass parameter 1 by reference'').}} | {{Parameter|$comment|integer|你想要获得的评论的ID。'''你必须传递一个包含整数的变数''' (例如 <tt>$id</tt>)。 literal 整数(例如<tt>7</tt>) 会导致严重的错误 (''Only variables can be passed for reference'' or ''Cannot pass parameter 1 by reference'').}} | ||
{{Parameter|$output|string|你希望结果怎样显示。 ''OBJECT'' <nowiki>=</nowiki> 作为 object, ''ARRAY_A'' <nowiki>=</nowiki> 作为值的field名称的相关数组, ''ARRAY_N'' <nowiki>=</nowiki> 作为field值的梯状数组。}} | {{Parameter|$output|string|你希望结果怎样显示。 ''OBJECT'' <nowiki>=</nowiki> 作为 object, ''ARRAY_A'' <nowiki>=</nowiki> 作为值的field名称的相关数组, ''ARRAY_N'' <nowiki>=</nowiki> 作为field值的梯状数组。}} | ||
==返回== | ==返回== | ||
返回的fields是: | 返回的fields是: | ||
; <tt>comment_ID</tt> : (''integer'') 评论 ID | ; <tt>comment_ID</tt> : (''integer'') 评论 ID | ||
; <tt>comment_post_ID</tt> : (''integer'') 相关文章的ID | ; <tt>comment_post_ID</tt> : (''integer'') 相关文章的ID | ||
; <tt>comment_author</tt> : (''string'')评论作者名 | ; <tt>comment_author</tt> : (''string'')评论作者名 | ||
; <tt>comment_author_email</tt> : (''string'')评论作者电子邮件 | ; <tt>comment_author_email</tt> : (''string'')评论作者电子邮件 | ||
; <tt>comment_author_url</tt> : (''string'')评论作者网页 | ; <tt>comment_author_url</tt> : (''string'')评论作者网页 | ||
; <tt>comment_author_IP</tt> : (''string'')评论作者IP | ; <tt>comment_author_IP</tt> : (''string'')评论作者IP | ||
; <tt>comment_date</tt> : (''string'')评论发表的时间(<tt>YYYY-MM-DD HH:MM:SS</tt>) | ; <tt>comment_date</tt> : (''string'')评论发表的时间(<tt>YYYY-MM-DD HH:MM:SS</tt>) | ||
; <tt>comment_date_gmt</tt> : (''string'')评论发表的格林尼治时间(<tt>YYYY-MM-DD HH:MM:SS</tt>) | ; <tt>comment_date_gmt</tt> : (''string'')评论发表的格林尼治时间(<tt>YYYY-MM-DD HH:MM:SS</tt>) | ||
; <tt>comment_content</tt> : (''string'')评论的内容 | ; <tt>comment_content</tt> : (''string'')评论的内容 | ||
; <tt>comment_karma</tt> : (''integer'')评论的karama | ; <tt>comment_karma</tt> : (''integer'')评论的karama | ||
; <tt>comment_approved</tt> : (''string'')评论审核(0, 1 或者 '垃圾广告') | ; <tt>comment_approved</tt> : (''string'')评论审核(0, 1 或者 '垃圾广告') | ||
; <tt>comment_agent</tt> : (''string'')评论的代理器(浏览器,操作系统,等等) | ; <tt>comment_agent</tt> : (''string'')评论的代理器(浏览器,操作系统,等等) | ||
; <tt>comment_type</tt> : (''string'')如果评论有意义,显示评论的类型(<tt>pingback|trackback</tt>),如果为一般的评论,为空 | ; <tt>comment_type</tt> : (''string'')如果评论有意义,显示评论的类型(<tt>pingback|trackback</tt>),如果为一般的评论,为空 | ||
; <tt>comment_parent</tt> : (''string'')上级评论的ID | ; <tt>comment_parent</tt> : (''string'')上级评论的ID | ||
; <tt>user_ID</tt> : (''integer'') 如果评论作者注册了,为评论作者的ID (否则为0) | ; <tt>user_ID</tt> : (''integer'') 如果评论作者注册了,为评论作者的ID (否则为0) | ||
== 参考 == | == 参考 == | ||
{{Copyedit}} | {{Copyedit}} |
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
- 正确的:传递一个需变数作为post_id
$the_comment = & get_comment( $dummy_id = 7 );
- 不正确的: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.