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

WBOY
发布: 2023-08-31 20:42:01
原创
787 人浏览过

第三批模板标签的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' );

?>
登录后复制

获取并显示 Feed 的评论作者姓名: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 );

?>
登录后复制

显示 Feed 的评论内容: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

  • $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 (可选—字符串)

    “评论”类型显示的文本。

    (默认:“评论”)

  • $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+指南的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!