Tuts+ Guide to the Third Batch of Template Tags
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 and display the comment author name: get_comment_author()
& comment_author()
These template tags return or display the commenter's name.
parameter
Two template tags only accept one parameter:
-
$comment_ID
(optional - integer) :The ID of the comment to use.
(Default: ID of current comment)
usage
<?php // Display the commenter's name. comment_author(); // Build an introduction of each comment. $comment_intro = get_comment_author() . __( ' says...', 'translation-domain' ); ?>
Get and display the feed's comment author name: 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.
parameter
These template tags do not accept any parameters.
usage
<?php comment_author_rss(); ?>
Get and display the email address of the comment author: 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.)
parameter
Two template tags only accept one parameter:
-
$comment_ID
(optional - integer) :The ID of the comment to use.
(Default: ID of current comment)
usage
<?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 and display the link to the comment author's email address: 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.
parameter
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)
usage
<?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 and display the commenter's URL: get_comment_author_url()
& comment_author_url()
These template tags allow you to return or display the URL of the review author's website.
parameter
Two template tags only accept one parameter:
-
$comment_ID
(optional - integer) :The ID of the comment to use.
(Default: ID of current comment)
usage
<?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 and display the commenter's link (with the author's name as anchor text): 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.
parameter
Two template tags only accept one parameter:
-
$comment_ID
(optional - integer) :The ID of the comment to use.
(Default: ID of current comment)
usage
<?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 and display the commenter's link (using custom text): 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.
parameter
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)
usage
<?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 and display the commenter’s IP address: get_comment_author_IP()
& comment_author_IP()
These template tags return or display the IP address of the comment author.
parameter
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 ); ?>
显示 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
) 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 ); ?>
获取并显示评论 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 ); ?>
结论
希望您喜欢第三批模板标签。还有五个批次要进行,请继续关注更多模板标签!
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

VSCode Setup in Chinese: A Complete Guide In software development, Visual Studio Code (VSCode for short) is a commonly used integrated development environment. For developers who use Chinese, setting VSCode to the Chinese interface can improve work efficiency. This article will provide you with a complete guide, detailing how to set VSCode to a Chinese interface and providing specific code examples. Step 1: Download and install the language pack. After opening VSCode, click on the left

With the launch of Windows 11, Microsoft has introduced some new features and updates, including a security feature called VBS (Virtualization-basedSecurity). VBS utilizes virtualization technology to protect the operating system and sensitive data, thereby improving system security. However, for some users, VBS is not a necessary feature and may even affect system performance. Therefore, this article will introduce how to turn off VBS in Windows 11 to help

Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

PHP7 Installation Directory Configuration Guide PHP is a popular server-side scripting language used to develop dynamic web pages. Currently, the latest version of PHP is PHP7, which introduces many new features and performance optimizations and is the preferred version for many websites and applications. When installing PHP7, it is very important to correctly configure the installation directory. This article will provide you with a detailed guide to configuring the PHP7 installation directory, with specific code examples. To download PHP7 first, you need to download it from the PHP official website (https://www.

Regarding PPT masking, many people must be unfamiliar with it. Most people do not understand it thoroughly when making PPT, but just make it up to make what they like. Therefore, many people do not know what PPT masking means, nor do they understand it. I know what this mask does, and I don’t even know that it can make the picture less monotonous. Friends who want to learn, come and learn, and add some PPT masks to your PPT pictures. Make it less monotonous. So, how to add a PPT mask? Please read below. 1. First we open PPT, select a blank picture, then right-click [Set Background Format] and select a solid color. 2. Click [Insert], word art, enter the word 3. Click [Insert], click [Shape]

When browsing Douyin works, we often see a clock icon behind the tag. So, what exactly is this clock? This article will focus on the discussion of "What is the clock behind the Douyin label", hoping to provide some useful reference for your use of Douyin. 1. What is the clock behind the Douyin label? Douyin will launch some hot topic challenges. When users participate, they will see a clock icon after the tag, which means that the work is participating in the topic challenge and displays the remaining time of the challenge. For some time-sensitive content, such as holidays, special events, etc., Douyin will attach a clock icon after the label to remind users of the validity period of the content. 3. Popular tags: When a tag becomes popular, Douyin will add a clock icon after the tag to indicate that the tag is

As a popular short video social platform, Douyin has a huge user base. For Douyin creators, using tags to attract traffic is an effective way to increase the exposure of content and attract attention. So, how does Douyin use tags to attract traffic? This article will answer this question in detail for you and introduce related techniques. 1. How to add tags on Douyin to attract traffic? When posting a video, make sure to choose tags that are relevant to the content. These tags should cover the topic and keywords of your video to make it easier for users to find your video through tags. Leveraging popular hashtags is an effective way to increase your video’s exposure. Research current popular tags and trends and incorporate them into your video descriptions and tags. These popular tags usually have higher visibility and can attract the attention of more viewers. 3. Label

Golang Desktop Application Development Guide With the popularity of the Internet and the advent of the digital age, desktop applications are playing an increasingly important role in our lives and work. As a powerful programming language, Golang (Go language) is gradually emerging in the field of desktop application development. This article will introduce you to how to use Golang to develop desktop applications and provide specific code examples to help you get started quickly and master development skills. First, we need to understand some basic concepts and tools. In Gol
