首頁  >  文章  >  後端開發  >  第三批模板標籤的Tuts+指南

第三批模板標籤的Tuts+指南

WBOY
WBOY原創
2023-08-31 20:41:09783瀏覽

第三批模板標籤的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) 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 );

?>

结论

希望您喜欢第三批模板标签。还有五个批次要进行,请继续关注更多模板标签!

如果您有任何問題、意見或更正,您可以在評論部分與我們分享您的想法。如果您喜歡這篇文章,請不要忘記與您的朋友分享!

以上是第三批模板標籤的Tuts+指南的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn