在本系列的第三部分中,我们介绍了第二批 wordpress 模板标签。在第四部分中,我们将介绍第三批近 200 个模板标签。在整个教程中,我们将看到有关评论的模板标签。
获取并显示评论作者姓名:get_comment_author() & comment_author()这些模板标签返回或显示评论者的姓名。
参数两个模板标签只接受一个参数:
$comment_id (可选 - 整数):要使用的评论的 id。
(默认:当前评论的 id)
用法<?php// display the commenter's name.comment_author();// build an introduction of each comment.$comment_intro = get_comment_author() . __( ' says...', 'translation-domain' );?>
获取并显示 feed 的评论作者姓名:get_comment_author_rss() & comment_author_rss()这些模板标签返回或回显评论作者的姓名,并使其准备好显示在提要上。
参数这些模板标记不接受任何参数。
用法<?phpcomment_author_rss();?>
获取并显示评论作者的电子邮件地址:get_comment_author_email() & comment_author_email()这些模板标签可让您返回或回显评论者的电子邮件地址。 (警告:在前端向公众显示评论者的电子邮件地址并不酷,因此请确保正确使用它。)
参数两个模板标签只接受一个参数:
$comment_id (可选 - 整数):
要使用的评论的 id。
(默认:当前评论的 id) 用法<?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()这些模板标签可让您以 mailto: 链接的形式返回或回显评论者的电子邮件地址。
参数两个模板标签都接受三个参数:
$linktext (可选—字符串):
要显示的文本,而不是评论作者的电子邮件地址。
(默认:电子邮件地址) $before (可选—字符串):
在输出之前显示的文本或 html 代码。
(默认:空) $after (可选—字符串):
输出后显示的文本或 html 代码。
(默认:空) 用法<?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 />' );?>
获取并显示评论者的 url:get_comment_author_url() & comment_author_url()这些模板标签可让您返回或显示评论作者网站的 url。
参数两个模板标签只接受一个参数:
$comment_id (可选 - 整数):
要使用的评论的 id。
(默认:当前评论的 id) 用法<?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()这些模板标签获取或回显评论者的网站链接,并将评论者的姓名作为锚文本。
参数两个模板标签只接受一个参数:
$comment_id (可选 - 整数):
要使用的评论的 id。
(默认:当前评论的 id) 用法<?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()这些模板标签允许您获取或回显评论者网站的链接,并以自定义文本作为锚点。
参数两个模板标签都接受三个参数:
$linktext (可选—字符串):
要显示的文本。
(默认:url) $before (可选—字符串):
在输出之前显示的文本或 html 代码。
(默认:空) $after (可选—字符串):
输出后显示的文本或 html 代码。
(默认:空) 用法<?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>' );?>
获取并显示评论者的ip地址:get_comment_author_ip() & comment_author_ip()这些模板标签返回或显示评论作者的 ip 地址。
参数两个模板标签只接受一个参数:
$comment_id (可选 - 整数):
要使用的评论的 id。
(默认:当前评论的 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 );?>
显示 feed 的评论内容:comment_text_rss()此模板标记获取评论内容并使其准备好在提要中显示。
参数此模板标记不接受任何参数。
用法<?phpcomment_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) $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 );?>
获取并显示评论 id:get_comment_id() & comment_id()这些模板标签的工作非常简单:它们获取评论的 id。
参数这些模板标记不接受任何参数。
用法<?phpcomment_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 );?>
结论希望您喜欢第三批模板标签。还有五个批次要进行,请继续关注更多模板标签!
如果您有任何问题、意见或更正,您可以在评论部分与我们分享您的想法。如果您喜欢这篇文章,请不要忘记与您的朋友分享!
以上就是第三批模板标签的tuts+指南的详细内容。