In part three of this series, we covered the second batch of WordPress template tags. In Part 4, we introduce the third batch of nearly 200 template tags. Throughout this tutorial we'll see template tags for comments.
get_comment_author()
& comment_author()
These template tags return or display the commenter's name.
Two template tags only accept one parameter:
$comment_ID
(optional - integer) : The ID of the comment to use.
(Default: ID of current comment)
<?php // Display the commenter's name. comment_author(); // Build an introduction of each comment. $comment_intro = get_comment_author() . __( ' says...', 'translation-domain' ); ?>
get_comment_author_rss()
& comment_author_rss()
These template tags return or echo the name of the comment author and prepare it for display on the feed.
These template tags do not accept any parameters.
<?php comment_author_rss(); ?>
get_comment_author_email()
& comment_author_email()
These template tags allow you to return or echo the commenter's email address. (Warning: It's not cool to display the commenter's email address to the public on the front end, so make sure you use it correctly.)
Two template tags only accept one parameter:
$comment_ID
(optional - integer) : The ID of the comment to use.
(Default: ID of current comment)
<?php // Get the email address of the commenter. comment_author_email(); // Return the email address of the commenter from a specific comment. $commenter_email = get_comment_author_email( 57 ); ?>
get_comment_author_email_link()
& comment_author_email_link()
These template tags allow you to return or echo the commenter's email address in the form of a mailto:
link.
Both template tags accept three parameters:
$linktext
(optional - string) : Text to display instead of the email address of the comment author.
(default: email address)
$before
(optional - string) : Text or HTML code to display before output.
(default: empty)
$after
(optional - string) : Text or HTML code to be displayed after output.
(default: empty)
<?php // Get the email link of the commenter. comment_author_email_link(); // Return the email link of the commenter. $commenter_email_link = get_comment_author_email_link( '<i class="icon-email"></i>', __( 'Comment Author\'s Email Address', 'translation-domain' ), '<br />' ); ?>
get_comment_author_url()
& comment_author_url()
These template tags allow you to return or display the URL of the review author's website.
Two template tags only accept one parameter:
$comment_ID
(optional - integer) : The ID of the comment to use.
(Default: ID of current comment)
<?php // Display the comment author url. comment_author_url(); // Return the comment author url. $commenter_URL = get_comment_author_url(); // Return a link to the comment author's website from a specific comment. $commenter_link = '<a href="' . get_comment_author_url( 988 ) . '">' . __( 'Comment Author\'s Website', 'translation-domain' ) . '</a>'; ?>
get_comment_author_link()
& comment_author_link()
These template tags get or echo the commenter's website link and use the commenter's name as anchor text.
Two template tags only accept one parameter:
$comment_ID
(optional - integer) : The ID of the comment to use.
(Default: ID of current comment)
<?php // Display the comment author's link. comment_author_link(); // Return the comment author's link from a specific comment. $commenter_link = get_comment_author_link( 452 ); ?>
get_comment_author_url_link()
& comment_author_url_link()
These template tags allow you to get or echo a link to the commenter's website, anchored with custom text.
Both template tags accept three parameters:
$linktext
(optional - string) : The text to be displayed.
(Default: URL)
$before
(optional - string) : Text or HTML code to display before output.
(default: empty)
$after
(optional - string) : Text or HTML code to be displayed after output.
(default: empty)
<?php // Display a customized "commenter's website" link. comment_author_url_link( __( 'Comment author\'s website', 'translation-domain' ) ); // Return a customized "commenter's website" link with $before and $after. $comment_author_website = get_comment_author_url_link( __( 'Comment author\'s website', 'translation-domain' ), '<span class="icon-website">', '</span>' ); ?>
get_comment_author_IP()
& comment_author_IP()
These template tags return or display the IP address of the comment author.
Two template tags only accept one parameter:
$comment_ID
(optional - integer) : The ID of the comment to use.
(默认:当前评论的 ID)
<?php // Display the comment author's IP. comment_author_IP(); // Display the comment author's IP from a specific comment. $commenter_IP = get_comment_author_IP( 41 ); ?>
get_comment_text()
& comment_text()
这些模板标签获取并显示评论的内容。
两个模板标签只接受一个参数:
$comment_ID
(可选 - 整数):要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Display the current comment's content. comment_text(); // Get a specific comment's content. $comment_content = get_comment_text( 965 ); ?>
comment_text_rss()
此模板标记获取评论内容并使其准备好在提要中显示。
此模板标记不接受任何参数。
<?php comment_text_rss(); ?>
get_comment_excerpt()
& comment_excerpt()
这些模板标签获取评论的内容并将其剪切以显示其“摘录”。
两个模板标签只接受一个参数:
$comment_ID
(可选 - 整数):要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Echo the current comment's excerpt. comment_excerpt(); // Return a given comment's excerpt. $comment_excerpt = get_comment_excerpt( 355 ); ?>
get_comment_date()
& comment_date()
这些模板标记回显或返回发布评论的日期。
两个模板标签都接受两个参数:
$date_format
(可选—字符串):日期的格式。
(默认:常规选项中设置的日期格式页)
$comment_ID
(可选 - 整数):要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Display the current comment's date. comment_date(); // Get a specific comment's date with a special date format. $some_comment_date = get_comment_date( 'MM/DD/YYYY', 9812 ); ?>
get_comment_time()
& comment_time()
这些模板标签返回或回显评论发布的时间。
get_comment_time()
接受三个参数:
$time_format
(可选—字符串):时间的格式。
(默认:常规选项中设置的时间格式页)
$gmt
(可选 - 布尔值):是否使用 GMT 日期。
(默认:FALSE
) EM>
$translate
(可选—布尔值):是否传递给 date_i18n()
函数来翻译日期。
(默认:TRUE
)
而 comment_time()
只接受一个参数:
$time_format
(可选—字符串):时间的格式。
(默认:常规选项中设置的时间格式页)
<?php // Display the current comment's time. comment_time(); // Get a specific comment's time with a special time format. $some_comment_time = get_comment_time( 'H:i:s', 115 ); ?>
get_comment_ID()
& comment_ID()
这些模板标签的工作非常简单:它们获取评论的 ID。
这些模板标记不接受任何参数。
<?php comment_ID(); ?>
comment_type()
此模板标记可让您显示评论的类型 - 普通评论、引用通告或 pingback。
此模板标记接受三个参数:
$commenttxt
(可选—字符串):“评论”类型显示的文本。
(默认:“评论”)
$trackbacktxt
(可选—字符串):为“引用引用”类型显示的文本。
(默认:“引用引用”)
$pingbacktxt
(可选 — 字符串):显示“pingback”类型的文本。
(默认:“Pingback”)
<?php // Display comment type with default texts. comment_type(); // Display comment type with custom texts. comment_type( __( 'Reaction', 'translation-domain' ), __( 'Trackback', 'translation-domain' ), __( 'Ping', 'translation-domain' ) ); ?>
get_avatar()
此模板标签可让您获取用户的“头像”。
此模板标记接受四个参数:
$id_or_email
(必需 — 字符串、整数或对象):用户 ID、电子邮件地址或评论对象。
(默认值:NULL
)
$size
(可选 - 整数):头像的大小(以像素为单位)。
(默认:96) >
$default
(可选 - 字符串):自定义“默认图像”的 URL(如果没有可用的头像)。
(默认值:空)
$alt
(可选—字符串):图像的替代文本(alt
参数)。
(默认: FALSE
)
<?php // Returns current comment author's avatar. $commenter_email = get_comment_author_email(); $commenter_avatar = get_avatar( $commenter_email, 512 ); ?>
希望您喜欢第三批模板标签。还有五个批次要进行,请继续关注更多模板标签!
If you have any questions, comments, or corrections, you can share your thoughts with us in the comments section. If you liked this article, don’t forget to share it with your friends!
The above is the detailed content of Tuts+ Guide to the Third Batch of Template Tags. For more information, please follow other related articles on the PHP Chinese website!