在本系列的第三部分中,我们介绍了第二批 WordPress 模板标签。在第四部分中,我们将介绍第三批近 200 个模板标签。在整个教程中,我们将看到有关评论的模板标签。
这些模板标签返回或显示评论者的姓名。
两个模板标签只接受一个参数:
要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Display the commenter's name. comment_author(); // Build an introduction of each comment. $comment_intro = get_comment_author() . __( ' says...', 'translation-domain' ); ?>
这些模板标签返回或回显评论作者的姓名,并使其准备好显示在提要上。
这些模板标记不接受任何参数。
<?php comment_author_rss(); ?>
这些模板标签可让您返回或回显评论者的电子邮件地址。 (警告:在前端向公众显示评论者的电子邮件地址并不酷,因此请确保正确使用它。)
两个模板标签只接受一个参数:
要使用的评论的 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 ); ?>
这些模板标签可让您以 mailto: 链接的形式返回或回显评论者的电子邮件地址。
两个模板标签都接受三个参数:
要显示的文本,而不是评论作者的电子邮件地址。
(默认:电子邮件地址)
在输出之前显示的文本或 HTML 代码。
(默认:空)
输出后显示的文本或 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。
两个模板标签只接受一个参数:
要使用的评论的 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>'; ?>
这些模板标签获取或回显评论者的网站链接,并将评论者的姓名作为锚文本。
两个模板标签只接受一个参数:
要使用的评论的 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 ); ?>
这些模板标签允许您获取或回显评论者网站的链接,并以自定义文本作为锚点。
两个模板标签都接受三个参数:
要显示的文本。
(默认:URL)
在输出之前显示的文本或 HTML 代码。
(默认:空)
输出后显示的文本或 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 地址。
两个模板标签只接受一个参数:
要使用的评论的 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 ); ?>
这些模板标签获取并显示评论的内容。
两个模板标签只接受一个参数:
要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Display the current comment's content. comment_text(); // Get a specific comment's content. $comment_content = get_comment_text( 965 ); ?>
此模板标记获取评论内容并使其准备好在提要中显示。
此模板标记不接受任何参数。
<?php comment_text_rss(); ?>
这些模板标签获取评论的内容并将其剪切以显示其“摘录”。
两个模板标签只接受一个参数:
要使用的评论的 ID。
(默认:当前评论的 ID)
<?php // Echo the current comment's excerpt. comment_excerpt(); // Return a given comment's excerpt. $comment_excerpt = get_comment_excerpt( 355 ); ?>
这些模板标记回显或返回发布评论的日期。
两个模板标签都接受两个参数:
日期的格式。
(默认:常规选项中设置的日期格式页)
要使用的评论的 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() 接受三个参数:
时间的格式。
(默认:常规选项中设置的时间格式页)
是否使用 GMT 日期。
(默认:FALSE) EM>
是否传递给 date_i18n() 函数来翻译日期。
(默认:TRUE)
而 comment_time() 只接受一个参数:
时间的格式。
(默认:常规选项中设置的时间格式页)
<?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。
这些模板标记不接受任何参数。
<?php comment_ID(); ?>
此模板标记可让您显示评论的类型 - 普通评论、引用通告或 pingback。
此模板标记接受三个参数:
“评论”类型显示的文本。
(默认:“评论”)
为“引用引用”类型显示的文本。
(默认:“引用引用”)
显示“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' ) ); ?>
此模板标签可让您获取用户的“头像”。
此模板标记接受四个参数:
用户 ID、电子邮件地址或评论对象。
(默认值:NULL)
头像的大小(以像素为单位)。
(默认:96) >
自定义“默认图像”的 URL(如果没有可用的头像)。
(默认值:空)
图像的替代文本(alt 参数)。
(默认: FALSE)
<?php // Returns current comment author's avatar. $commenter_email = get_comment_author_email(); $commenter_avatar = get_avatar( $commenter_email, 512 ); ?>
希望您喜欢第三批模板标签。还有五个批次要进行,请继续关注更多模板标签!
如果您有任何问题、意见或更正,您可以在评论部分与我们分享您的想法。如果您喜欢这篇文章,请不要忘记与您的朋友分享!
以上就是第三批模板标签的Tuts+指南的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号