Rumah  >  Artikel  >  pembangunan bahagian belakang  >  Panduan Tuts+ untuk Teg Templat Kelompok Ketiga

Panduan Tuts+ untuk Teg Templat Kelompok Ketiga

WBOY
WBOYasal
2023-08-31 20:41:09784semak imbas

Panduan Tuts+ untuk Teg Templat Kelompok Ketiga

Dalam bahagian tiga siri ini, kami merangkumi kumpulan kedua teg templat WordPress. Dalam Bahagian 4, kami memperkenalkan kumpulan ketiga hampir 200 teg templat. Sepanjang tutorial ini kita akan melihat teg templat untuk ulasan.

Dapatkan dan paparkan nama pengarang ulasan: get_comment_author() & comment_author()

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_IDTag templat ini mengembalikan atau memaparkan nama pengulas.

    Parameter

    Dua teg templat hanya menerima satu parameter:
    • $comment_ID

      (pilihan - integer)

      : 🎜🎜ID ulasan untuk digunakan. 🎜🎜🎜 (lalai: ID ulasan semasa) 🎜

    Penggunaan

    <?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 );
    
    ?>
    
    🎜Dapatkan dan paparkan nama pengarang ulasan suapan: get_comment_author_rss() & comment_author_rss() 🎜Teg templat ini mengembalikan atau menggemakan nama pengarang ulasan dan sediakannya untuk dipaparkan pada suapan. 🎜

    Parameter

    🎜Teg templat ini tidak menerima sebarang parameter. 🎜

    Penggunaan

    <?php
    
    // Display the current comment's content.
    comment_text();
    
    // Get a specific comment's content.
    $comment_content = get_comment_text( 965 );
    
    ?>
    
    🎜Dapatkan dan paparkan alamat e-mel pengarang ulasan: get_comment_author_email() & comment_author_email() 🎜Teg templat ini membolehkan anda mengembalikan atau menggemakan alamat e-mel pengulas. (Amaran: Tidak sesuai untuk memaparkan alamat e-mel pengulas kepada orang ramai di bahagian hadapan, jadi pastikan anda menggunakannya dengan betul.) 🎜

    Parameter

    🎜Dua teg templat hanya menerima satu parameter: 🎜
    • $comment_ID 🎜 (pilihan - integer) 🎜: 🎜🎜ID ulasan untuk digunakan. 🎜🎜🎜 (lalai: ID ulasan semasa) 🎜

    Penggunaan

    <?php
    
    comment_text_rss();
    
    ?>
    
    🎜Dapatkan dan paparkan pautan ke alamat e-mel pengarang ulasan: get_comment_author_email_link() & comment_author_email_link() 🎜Teg templat ini membolehkan anda mengembalikan atau menggemakan alamat e-mel pengulas dalam bentuk pautan mailto:. 🎜

    Parameter

    🎜Kedua-dua teg templat menerima tiga parameter: 🎜
    • $linktext 🎜 (pilihan — rentetan) 🎜: 🎜🎜Teks untuk dipaparkan dan bukannya alamat e-mel pengarang ulasan. 🎜🎜🎜(lalai: alamat e-mel)🎜
    • $before 🎜 (pilihan — rentetan) 🎜: 🎜🎜Kod teks atau HTML untuk dipaparkan sebelum output. 🎜🎜🎜 (lalai: kosong) 🎜
    • $after 🎜 (pilihan - rentetan) 🎜: 🎜🎜Teks atau kod HTML untuk dipaparkan selepas output. 🎜🎜🎜 (lalai: kosong) 🎜

    Penggunaan

    <?php
    
    // Echo the current comment's excerpt.
    comment_excerpt();
    
    // Return a given comment's excerpt.
    $comment_excerpt = get_comment_excerpt( 355 );
    
    ?>
    
    🎜Dapatkan dan paparkan URL pengulas: get_comment_author_url() & comment_author_url() 🎜Teg templat ini membolehkan anda memulangkan atau memaparkan URL tapak web pengarang ulasan. 🎜

    Parameter

    🎜Dua teg templat hanya menerima satu parameter: 🎜
    • $comment_ID 🎜 (pilihan - integer) 🎜: 🎜🎜ID ulasan untuk digunakan. 🎜🎜🎜 (lalai: ID ulasan semasa) 🎜

    Penggunaan

    <?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 );
    
    ?>
    
    🎜Dapatkan dan paparkan pautan pengulas (dengan nama pengarang sebagai teks utama): get_comment_author_link() & comment_author_link() 🎜Teg templat ini mendapatkan atau menggemakan pautan tapak web pengulas dan menyertakan nama pengulas sebagai teks utama. 🎜

    Parameter

    🎜Dua teg templat hanya menerima satu parameter: 🎜
    • $comment_ID 🎜 (pilihan - integer) 🎜: 🎜🎜ID ulasan untuk digunakan. 🎜🎜🎜 (lalai: ID ulasan semasa) 🎜

    Penggunaan

    <?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 );
    
    ?>
    
    🎜Dapatkan dan paparkan pautan pengulas (menggunakan teks tersuai): get_comment_author_url_link() & comment_author_url_link() 🎜Teg templat ini membolehkan anda mendapatkan atau menggemakan pautan ke tapak web pengulas, berlabuh dengan teks tersuai. 🎜

    Parameter

    🎜Kedua-dua teg templat menerima tiga parameter: 🎜
    • $linktext 🎜 (pilihan - rentetan) 🎜: 🎜🎜Teks yang akan dipaparkan. 🎜🎜🎜(Lalai: URL)🎜
    • $before 🎜 (pilihan — rentetan) 🎜: 🎜🎜Kod teks atau HTML untuk dipaparkan sebelum output. 🎜🎜🎜 (lalai: kosong) 🎜
    • $after 🎜 (pilihan - rentetan) 🎜: 🎜🎜Teks atau kod HTML untuk dipaparkan selepas output. 🎜🎜🎜 (lalai: kosong) 🎜

    Penggunaan

    <?php
    
    comment_ID();
    
    ?>
    
    🎜Dapatkan dan paparkan alamat IP pengulas: get_comment_author_IP() & comment_author_IP() 🎜Teg templat ini mengembalikan atau memaparkan alamat IP pengarang ulasan. 🎜

    Parameter

    🎜Dua teg templat hanya menerima satu parameter: 🎜
    • $comment_ID 🎜 (pilihan - integer) 🎜: 🎜🎜ID ulasan untuk digunakan. 🎜

      (默认:当前评论的 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 );
    
    ?>
    

    结论

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

    Jika anda mempunyai sebarang soalan, komen atau pembetulan, anda boleh berkongsi pendapat anda dengan kami di bahagian komen. Jika anda menyukai artikel ini, jangan lupa untuk berkongsi dengan rakan anda!

Atas ialah kandungan terperinci Panduan Tuts+ untuk Teg Templat Kelompok Ketiga. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn