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!

PHPsessionscanstorestrings,numbers,arrays,andobjects.1.Strings:textdatalikeusernames.2.Numbers:integersorfloatsforcounters.3.Arrays:listslikeshoppingcarts.4.Objects:complexstructuresthatareserialized.

TostartaPHPsession,usesession_start()atthescript'sbeginning.1)Placeitbeforeanyoutputtosetthesessioncookie.2)Usesessionsforuserdatalikeloginstatusorshoppingcarts.3)RegeneratesessionIDstopreventfixationattacks.4)Considerusingadatabaseforsessionstoragei

Session regeneration refers to generating a new session ID and invalidating the old ID when the user performs sensitive operations in case of session fixed attacks. The implementation steps include: 1. Detect sensitive operations, 2. Generate new session ID, 3. Destroy old session ID, 4. Update user-side session information.

PHP sessions have a significant impact on application performance. Optimization methods include: 1. Use a database to store session data to improve response speed; 2. Reduce the use of session data and only store necessary information; 3. Use a non-blocking session processor to improve concurrency capabilities; 4. Adjust the session expiration time to balance user experience and server burden; 5. Use persistent sessions to reduce the number of data read and write times.

PHPsessionsareserver-side,whilecookiesareclient-side.1)Sessionsstoredataontheserver,aremoresecure,andhandlelargerdata.2)Cookiesstoredataontheclient,arelesssecure,andlimitedinsize.Usesessionsforsensitivedataandcookiesfornon-sensitive,client-sidedata.

PHPidentifiesauser'ssessionusingsessioncookiesandsessionIDs.1)Whensession_start()iscalled,PHPgeneratesauniquesessionIDstoredinacookienamedPHPSESSIDontheuser'sbrowser.2)ThisIDallowsPHPtoretrievesessiondatafromtheserver.

The security of PHP sessions can be achieved through the following measures: 1. Use session_regenerate_id() to regenerate the session ID when the user logs in or is an important operation. 2. Encrypt the transmission session ID through the HTTPS protocol. 3. Use session_save_path() to specify the secure directory to store session data and set permissions correctly.

PHPsessionfilesarestoredinthedirectoryspecifiedbysession.save_path,typically/tmponUnix-likesystemsorC:\Windows\TemponWindows.Tocustomizethis:1)Usesession_save_path()tosetacustomdirectory,ensuringit'swritable;2)Verifythecustomdirectoryexistsandiswrita


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

Zend Studio 13.0.1
Powerful PHP integrated development environment

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
