comment_type()
云策文档标注
概述
comment_type() 函数用于显示当前评论的类型,如评论、Trackback 或 Pingback。它接受可选参数来自定义输出文本,并基于 get_comment_type() 的返回值进行条件输出。
关键要点
- 函数用于输出当前评论的类型,支持自定义显示文本。
- 参数包括 $comment_text、$trackback_text 和 $pingback_text,均为可选,默认为 false 时使用翻译字符串。
- 内部使用 get_comment_type() 获取类型,并通过 switch 语句决定输出内容。
- 相关函数包括 get_comment_type()、_x() 和 __(),用于类型检索和本地化。
代码示例
function comment_type( $comment_text = false, $trackback_text = false, $pingback_text = false ) {
if ( false === $comment_text ) {
$comment_text = _x( 'Comment', 'noun' );
}
if ( false === $trackback_text ) {
$trackback_text = __( 'Trackback' );
}
if ( false === $pingback_text ) {
$pingback_text = __( 'Pingback' );
}
$type = get_comment_type();
switch ( $type ) {
case 'trackback':
echo $trackback_text;
break;
case 'pingback':
echo $pingback_text;
break;
default:
echo $comment_text;
}
}
原文内容
Displays the comment type of the current comment.
Parameters
$comment_textstring|falseoptional-
String to display for comment type.
Default:
false $trackback_textstring|falseoptional-
String to display for trackback type.
Default:
false $pingback_textstring|falseoptional-
String to display for pingback type.
Default:
false
Source
function comment_type( $comment_text = false, $trackback_text = false, $pingback_text = false ) {
if ( false === $comment_text ) {
$comment_text = _x( 'Comment', 'noun' );
}
if ( false === $trackback_text ) {
$trackback_text = __( 'Trackback' );
}
if ( false === $pingback_text ) {
$pingback_text = __( 'Pingback' );
}
$type = get_comment_type();
switch ( $type ) {
case 'trackback':
echo $trackback_text;
break;
case 'pingback':
echo $pingback_text;
break;
default:
echo $comment_text;
}
}
Changelog
| Version | Description |
|---|---|
| 0.71 | Introduced. |
Skip to note 2 content
Codex
Basic Example
<p> to : </p>