Tuts +模板标签指南:第三批

在本系列的第三部分中,我们介绍了第二批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' );

?>

获取并显示供稿的评论作者姓名: get_comment_author_rss()comment_author_rss()

这些模板标记返回或回显评论作者的名称,并使其准备显示在提要上。

参量

这些模板标记不接受任何参数。

用法

<?php

comment_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 );

?>

显示供稿评论的内容: 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 (可选-布尔值)
    是否使用格林尼治标准时间。
    (默认: 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。

参量

这些模板标记不接受任何参数。

用法

<?php

comment_ID();

?>

显示评论的类型comment_type()

使用此模板标记,您可以显示评论的类型-普通评论,引用或pingback。

参量

此模板标记接受三个参数:

  • $commenttxt (可选-字符串)
    用于显示“注释”类型的文本。
    (默认:'Comment')
  • $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 (可选-字符串)
    自定义“默认图片”的网址(如果没有可用的头像)。
    (默认:空)
  • $alt (可选-字符串)
    图片的替代文字( alt参数)。
    (默认: FALSE

用法

<?php

// Returns current comment author's avatar.
$commenter_email = get_comment_author_email();
$commenter_avatar = get_avatar( $commenter_email, 512 );

?>

结论

希望您喜欢第三批模板标签。 还有五个批次,敬请期待更多模板标签!

如果您有任何疑问,评论或更正,可以在“评论”部分与我们分享您的想法。 而且,如果您喜欢这篇文章,请不要忘记与您的朋友分享!

翻译自: https://code.tutsplus.com/tutorials/the-tuts-guide-to-template-tags-third-batch--cms-22577

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值