簡體   English   中英

關於Wordpress get_the_title函數的困惑

[英]Confusions about Wordpress get_the_title function

功能:

 /**
 * Retrieve post title.
 *
 * If the post is protected and the visitor is not an admin, then "Protected"
 * will be displayed before the post title. If the post is private, then
 * "Private" will be located before the post title.
 *
 * @since 0.71
 *
 * @param int $id Optional. Post ID.
 * @return string
 */

function get_the_title( $id = 0 ) {
    $post = &get_post($id);

$title = isset($post->post_title) ? $post->post_title : '';
$id = isset($post->ID) ? $post->ID : (int) $id;

if ( !is_admin() ) {
    if ( !empty($post->post_password) ) {
        $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
        $title = sprintf($protected_title_format, $title);
    } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
        $private_title_format = apply_filters('private_title_format', __('Private: %s'));
        $title = sprintf($private_title_format, $title);
    }
}
return apply_filters( 'the_title', $title, $id );
}

我不明白參數__('Protected: %s')在下面的特定代碼行中的含義。 這是什么樣的參數?

$protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));

__()是一個本地化函數,用於獲取英語單詞“ Protected”的本地化字符串。

%ssprintf()使用的替換參數。 基本上,它將其替換為博客文章的標題。

整個__('Protected: %s')調用都作為參數傳遞給apply_filters()函數,以簡單地設置帖子標題的格式。 默認情況下,我認為什么都不會發生,但是插件可能會鈎上protected_title_format過濾器,以便在應用帖子標題之前進一步處理該格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM