WordPress: Function Reference/get comment:修订间差异
(新页面: ==Description== Takes a comment ID and returns the database record for that post. You can specify, by means of the <tt>$output</tt> parameter, how you would like the results returned. =...) |
无编辑摘要 |
||
第1行: | 第1行: | ||
==Description== | ==Description== | ||
== 描述== | |||
Takes a comment ID and returns the database record for that post. You can specify, by means of the <tt>$output</tt> parameter, how you would like the results returned. | Takes a comment ID and returns the database record for that post. You can specify, by means of the <tt>$output</tt> parameter, how you would like the results returned. | ||
获得评论ID,返回文章的数据库记录。你可以根据<tt>$output</tt>参数,规定结果的返回方式。 | |||
==Usage== | ==Usage== | ||
== 用法 == | |||
%%%<?php get_comment($id, $output); ?> %%% | |||
%%%<?php get_comment($id, $output); ?> %%% | %%%<?php get_comment($id, $output); ?> %%% | ||
==Example== | ==Example== | ||
== 例子 == | |||
To get the author's name of a comment with ID 7: | To get the author's name of a comment with ID 7: | ||
得到评论ID为7的作者名: | |||
%%%<?php | |||
$my_id = 7; | |||
$comment_id_7 = get_comment($my_id); | |||
$name = $comment_id_7->comment_author; | |||
?> %%% | |||
%%%<?php | %%%<?php | ||
第18行: | 第34行: | ||
Alternatively, specify the <tt>$output</tt> parameter: | Alternatively, specify the <tt>$output</tt> parameter: | ||
另外,规定<tt>$output</tt>参数: | |||
%%%<?php | |||
$my_id = 7; | |||
$comment_id_7 = get_comment($my_id, ARRAY_A); | |||
$name = $comment_id_7['comment_author']; | |||
?> %%% | |||
%%%<?php | |||
%%%<?php | %%%<?php | ||
第26行: | 第51行: | ||
%%%<?php | %%%<?php | ||
## Correct: pass a dummy variable as post_id | ## Correct: pass a dummy variable as post_id | ||
$the_comment = & get_comment( $dummy_id = 7 ); | $the_comment = & get_comment( $dummy_id = 7 ); | ||
##正确的:传递一个需变数作为post_id | |||
$the_comment = & get_comment( $dummy_id = 7 ); | |||
## Incorrect: literal integer as post_id | ## Incorrect: literal integer as post_id | ||
$the_comment = & get_comment( 7 ); | $the_comment = & get_comment( 7 ); | ||
##不正确的:literal整数作为post_id | |||
$the_comment = & get_comment( 7 ); | |||
// Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference' | // Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference' | ||
?>%%% | |||
// 致命的错误: '只有变数可以为reference传递' or 'Cannot pass parameter 1 by reference' | |||
?>%%% | ?>%%% | ||
==Parameters== | ==Parameters== | ||
== 参数 == | |||
{{Parameter|$comment|integer|The ID of the comment you'd like to fetch. '''You must pass a variable containing an integer''' (e.g. <tt>$id</tt>). A literal integer (e.g. <tt>7</tt>) will cause a fatal error (''Only variables can be passed for reference'' or ''Cannot pass parameter 1 by reference'').}} | {{Parameter|$comment|integer|The ID of the comment you'd like to fetch. '''You must pass a variable containing an integer''' (e.g. <tt>$id</tt>). A literal integer (e.g. <tt>7</tt>) will cause a fatal error (''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|How you'd like the result. ''OBJECT'' <nowiki>=</nowiki> as an object, ''ARRAY_A'' <nowiki>=</nowiki> as an associative array of field names to values, and ''ARRAY_N'' <nowiki>=</nowiki> a scalar array of field values.}} | {{Parameter|$output|string|How you'd like the result. ''OBJECT'' <nowiki>=</nowiki> as an object, ''ARRAY_A'' <nowiki>=</nowiki> as an associative array of field names to values, and ''ARRAY_N'' <nowiki>=</nowiki> a scalar array of field values.}} | ||
{{Parameter|$output|string|你希望结果怎样显示。 ''OBJECT'' <nowiki>=</nowiki> 作为 object, ''ARRAY_A'' <nowiki>=</nowiki> 作为值的field名称的相关数组, ''ARRAY_N'' <nowiki>=</nowiki> 作为field值的梯状数组。}} | |||
==Return== | ==Return== | ||
==返回== | |||
The fields returned are: | The fields returned are: | ||
返回的fields是: | |||
; <tt>comment_ID</tt> : (''integer'') The comment ID | |||
; <tt>comment_ID</tt> : (''integer'') 评论 ID | |||
; <tt>comment_post_ID</tt> : (''integer'') The post ID of the associated post | ; <tt>comment_post_ID</tt> : (''integer'') The post ID of the associated post | ||
; <tt>comment_post_ID</tt> : (''integer'') 相关文章的ID | |||
; <tt>comment_author</tt> : (''string'') The comment author's name | ; <tt>comment_author</tt> : (''string'') The comment author's name | ||
; <tt>comment_author</tt> : (''string'')评论作者名 | |||
; <tt>comment_author_email</tt> : (''string'') The comment author's email | ; <tt>comment_author_email</tt> : (''string'') The comment author's email | ||
; <tt>comment_author_email</tt> : (''string'')评论作者电子邮件 | |||
; <tt>comment_author_url</tt> : (''string'') The comment author's webpage | ; <tt>comment_author_url</tt> : (''string'') The comment author's webpage | ||
; <tt>comment_author_url</tt> : (''string'')评论作者网页 | |||
; <tt>comment_author_IP</tt> : (''string'') The comment author's IP | ; <tt>comment_author_IP</tt> : (''string'') The comment author's IP | ||
; <tt>comment_author_IP</tt> : (''string'')评论作者IP | |||
; <tt>comment_date</tt> : (''string'') The datetime of the comment (<tt>YYYY-MM-DD HH:MM:SS</tt>) | ; <tt>comment_date</tt> : (''string'') The datetime of the comment (<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'') The GMT datetime of the comment (<tt>YYYY-MM-DD HH:MM:SS</tt>) | ; <tt>comment_date_gmt</tt> : (''string'') The GMT datetime of the comment (<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'') The comment's contents | ; <tt>comment_content</tt> : (''string'') The comment's contents | ||
; <tt>comment_content</tt> : (''string'')评论的内容 | |||
; <tt>comment_karma</tt> : (''integer'') The comment's karma | ; <tt>comment_karma</tt> : (''integer'') The comment's karma | ||
; <tt>comment_karma</tt> : (''integer'')评论的karama | |||
; <tt>comment_approved</tt> : (''string'') The comment approbation (0, 1 or 'spam') | ; <tt>comment_approved</tt> : (''string'') The comment approbation (0, 1 or 'spam') | ||
; <tt>comment_approved</tt> : (''string'')评论审核(0, 1 或者 '垃圾广告') | |||
; <tt>comment_agent</tt> : (''string'') The comment's agent (browser, Operating System, etc.) | ; <tt>comment_agent</tt> : (''string'') The comment's agent (browser, Operating System, etc.) | ||
; <tt>comment_agent</tt> : (''string'')评论的代理器(浏览器,操作系统,等等) | |||
; <tt>comment_type</tt> : (''string'') The comment's type if meaningfull (<tt>pingback|trackback</tt>), and empty for normal comments | ; <tt>comment_type</tt> : (''string'') The comment's type if meaningfull (<tt>pingback|trackback</tt>), and empty for normal comments | ||
; <tt>comment_type</tt> : (''string'')如果评论有意义,显示评论的类型(<tt>pingback|trackback</tt>),如果为一般的评论,为空 | |||
; <tt>comment_parent</tt> : (''string'') The parent comment's ID | ; <tt>comment_parent</tt> : (''string'') The parent comment's ID | ||
; <tt>comment_parent</tt> : (''string'')上级评论的ID | |||
; <tt>user_ID</tt> : (''integer'') The comment author's ID if he is registered (0 otherwise) | ; <tt>user_ID</tt> : (''integer'') The comment author's ID if he is registered (0 otherwise) | ||
; <tt>user_ID</tt> : (''integer'') 如果评论作者注册了,为评论作者的ID (否则为0) | |||
== References == | == References == | ||
{{Copyedit}} | |||
== 参考 == | |||
{{Copyedit}} | {{Copyedit}} |
2008年7月21日 (一) 13:52的版本
Description
描述
Takes a comment ID and returns the database record for that post. You can specify, by means of the $output parameter, how you would like the results returned.
获得评论ID,返回文章的数据库记录。你可以根据$output参数,规定结果的返回方式。
Usage
用法
%%%<?php get_comment($id, $output); ?> %%%
%%%<?php get_comment($id, $output); ?> %%%
Example
例子
To get the author's name of a comment with ID 7: 得到评论ID为7的作者名: %%%<?php $my_id = 7; $comment_id_7 = get_comment($my_id); $name = $comment_id_7->comment_author; ?> %%%
%%%<?php $my_id = 7; $comment_id_7 = get_comment($my_id); $name = $comment_id_7->comment_author; ?> %%%
Alternatively, specify the $output parameter: 另外,规定$output参数: %%%<?php $my_id = 7; $comment_id_7 = get_comment($my_id, ARRAY_A); $name = $comment_id_7['comment_author']; ?> %%%
%%%<?php
%%%<?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 );
- 正确的:传递一个需变数作为post_id
$the_comment = & get_comment( $dummy_id = 7 );
- Incorrect: literal integer as post_id
$the_comment = & get_comment( 7 );
- 不正确的:literal整数作为post_id
$the_comment = & get_comment( 7 );
// Fatal error: 'Only variables can be passed for reference' or 'Cannot pass parameter 1 by reference' ?>%%%
// 致命的错误: '只有变数可以为reference传递' or 'Cannot pass parameter 1 by reference' ?>%%%
Parameters
参数
Return
返回
The fields returned are: 返回的fields是:
- comment_ID
- (integer) The comment ID
- comment_ID
- (integer) 评论 ID
- comment_post_ID
- (integer) The post ID of the associated post
- comment_post_ID
- (integer) 相关文章的ID
- comment_author
- (string) The comment author's name
- comment_author
- (string)评论作者名
- comment_author_email
- (string) The comment author's email
- comment_author_email
- (string)评论作者电子邮件
- comment_author_url
- (string) The comment author's webpage
- comment_author_url
- (string)评论作者网页
- comment_author_IP
- (string) The comment author's IP
- comment_author_IP
- (string)评论作者IP
- comment_date
- (string) The datetime of the comment (YYYY-MM-DD HH:MM:SS)
- comment_date
- (string)评论发表的时间(YYYY-MM-DD HH:MM:SS)
- comment_date_gmt
- (string) The GMT datetime of the comment (YYYY-MM-DD HH:MM:SS)
- comment_date_gmt
- (string)评论发表的格林尼治时间(YYYY-MM-DD HH:MM:SS)
- comment_content
- (string) The comment's contents
- comment_content
- (string)评论的内容
- comment_karma
- (integer) The comment's karma
- comment_karma
- (integer)评论的karama
- comment_approved
- (string) The comment approbation (0, 1 or 'spam')
- comment_approved
- (string)评论审核(0, 1 或者 '垃圾广告')
- comment_agent
- (string) The comment's agent (browser, Operating System, etc.)
- comment_agent
- (string)评论的代理器(浏览器,操作系统,等等)
- comment_type
- (string) The comment's type if meaningfull (pingback|trackback), and empty for normal comments
- comment_type
- (string)如果评论有意义,显示评论的类型(pingback|trackback),如果为一般的评论,为空
- comment_parent
- (string) The parent comment's ID
- comment_parent
- (string)上级评论的ID
- user_ID
- (integer) The comment author's ID if he is registered (0 otherwise)
- user_ID
- (integer) 如果评论作者注册了,为评论作者的ID (否则为0)
References
This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.
参考
This article is [[WordPress::Category:Copyedits|marked]] as in need of editing. You can help Codex by editing it.