The Tuts+ Guide to Template Tags: Third Batch

In the third part of the series, we went through the second batch of WordPress template tags. In this fourth part, we're going to go through the third batch of the almost 200 template tags. Throughout the tutorial, we'll see template tags about comments.

Getting & Displaying the Comment Author's Name: get_comment_author() & comment_author()

These template tags return or display the name of the commenter.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying the Comment Author's Name for Feeds: get_comment_author_rss() & comment_author_rss()

These template tags return or echo the comment author's name and makes it ready to display on feeds.

Parameters

These template tags don't accept any parameters.

Usage

Getting & Displaying the Comment Author's Email Address: get_comment_author_email() & comment_author_email()

These template tags let you return or echo the email address of the commenter. (Warning: It's not cool to display commenters' email addresses in the front-end to the public, so make sure you're using it right.)

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying a Link of the Comment Author's Email Address: get_comment_author_email_link() & comment_author_email_link()

These template tags let you return or echo the commenter's email address as a mailto: link.

Parameters

Both template tags accept three parameters:

  • $linktext (optional—string):
    Text to display instead of the comment author's email address.
    (Default: The email address)
  • $before (optional—string):
    The text or HTML code to display before the output.
    (Default: Empty)
  • $after (optional—string):
    The text or HTML code to display after the output.
    (Default: Empty)

Usage

Getting & Displaying the URL of the Commenter: get_comment_author_url() & comment_author_url()

These template tags let you return or display the URL of the website of the comment author.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying the Link of the Commenter (With Author Name as Anchor Text): get_comment_author_link() & comment_author_link()

These template tags get or echo the website link of the commenter with the commenter's name as the anchor text.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying the Link of the Commenter (With Custom Text): get_comment_author_url_link() & comment_author_url_link()

These template tags allow you to get or echo the link of the commenter's website with a custom text as the anchor.

Parameters

Both template tags accept three parameters:

  • $linktext (optional—string):
    Text to display.
    (Default: The URL)
  • $before (optional—string):
    The text or HTML code to display before the output.
    (Default: Empty)
  • $after (optional—string):
    The text or HTML code to display after the output.
    (Default: Empty)

Usage

Getting & Displaying the IP Address of the Commenter: get_comment_author_IP() & comment_author_IP()

These template tags return or display the IP address of the comment author.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying the Content of the Comment: get_comment_text() & comment_text()

These template tags get and display the comment's content.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: Current comment's ID)

Usage

Displaying the Content of the Comment for Feeds: comment_text_rss()

This template tag takes the comment content and makes it ready to display in feeds.

Parameters

This template tag doesn't accept any parameters.

Usage

Getting & Displaying the Excerpt of the Comment: get_comment_excerpt() & comment_excerpt()

These template tags take the comment's content and cut it to show an "excerpt" of it.

Parameters

Both template tags accept only one parameter:

  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: current comment's ID)

Usage

Getting & Displaying the Date of the Comment: get_comment_date() & comment_date()

These template tags echo or return the date when the comment was posted.

Parameters

Both template tags accept two parameters:

  • $date_format (optional—string):
    The format of the date.
    (Default: Date format set in the General Options page)
  • $comment_ID (optional—integer):
    The ID of the comment to work with.
    (Default: Current comment's ID)

Usage

Getting & Displaying the Time of the Comment: get_comment_time() & comment_time()

These template tags return or echo the time the comment was posted.

Parameters

get_comment_time() accepts three parameters:

  • $time_format (optional—string):
    The format of the time.
    (Default: Time format set in the General Options page)
  • $gmt (optional—boolean):
    Whether to use the GMT date.
    (Default: FALSE)
  • $translate (optional—boolean):
    Whether to pass to date_i18n() function to translate the date.
    (Default: TRUE)

And comment_time() accepts only one parameter:

  • $time_format (optional—string):
    The format of the time.
    (Default: Time format set in the General Options page)

Usage

Getting & Displaying the ID of the Comment: get_comment_ID() & comment_ID()

These template tags do a very simple job: They get the ID of the comment.

Parameters

These template tags don't accept any parameters.

Usage

Displaying the Type of the Comment: comment_type()

This template tag lets you display the type of the comment—a normal comment, a trackback, or a pingback.

Parameters

This template tag accepts three parameters:

  • $commenttxt (optional—string):
    Text to display for "comment" type.
    (Default: 'Comment' )
  • $trackbacktxt (optional—string):
    Text to display for "trackback" type.
    (Default: 'Trackback')
  • $pingbacktxt (optional—string):
    Text to display for "pingback" type.
    (Default: 'Pingback')

Usage

Getting the Avatar of a User: get_avatar()

This template tag lets you get the "avatar" of a user.

Parameters

This template tag accepts four parameters:

  • $id_or_email (required—string, integer or object):
    A user ID, email address, or comment object.
    (Default: NULL)
  • $size (optional—integer):
    The size of the avatar in pixels.
    (Default: 96)
  • $default (optional—string):
    URL of the custom "default image", if there's no avatar available.
    (Default: Empty)
  • $alt (optional—string):
    The alternative text (alt parameter) for the image.
    (Default: FALSE)

Usage

Conclusion

Hope you liked this third batch of template tags. There are five more batches to go, so stay tuned for more template tags!

If you have any questions, comments or corrections, you can share your thoughts with us in the Comments section. And if you liked the article, don't forget to share it with your friends!

Tags:

Comments

Related Articles