get_the_title()
参照:WordPress Codex-get_the_title()
構文
get_the_title($id[オプション]);
get_the_title()の詳細
動 作
引数の投稿IDに応じた投稿のタイトルを取得。
返り値
投稿のタイトル
引 数
$id[オプション]
整数/オブジェクト 投稿のID
(デフォルト)null 現在の投稿
get_the_title()のコード
参照:wp-includes/post-template.php
<?php 105 /** 106 * Retrieve post title. 107 * 108 * If the post is protected and the visitor is not an admin, then "Protected" 109 * will be displayed before the post title. If the post is private, then 110 * "Private" will be located before the post title. 111 * 112 * @since 0.71 113 * 114 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post. 115 * @return string 116 */ 117 function get_the_title( $post = 0 ) { 118 $post = get_post( $post ); 119 120 $title = isset( $post->post_title ) ? $post->post_title : ''; 121 $id = isset( $post->ID ) ? $post->ID : 0; 122 123 if ( ! is_admin() ) { 124 if ( ! empty( $post->post_password ) ) { 125 126 /* translators: %s: Protected post title. */ 127 $prepend = __( 'Protected: %s' ); 128 129 /** 130 * Filters the text prepended to the post title for protected posts. 131 * 132 * The filter is only applied on the front end. 133 * 134 * @since 2.8.0 135 * 136 * @param string $prepend Text displayed before the post title. 137 * Default 'Protected: %s'. 138 * @param WP_Post $post Current post object. 139 */ 140 $protected_title_format = apply_filters( 'protected_title_format', $prepend, $post ); 141 $title = sprintf( $protected_title_format, $title ); 142 } elseif ( isset( $post->post_status ) && 'private' == $post->post_status ) { 143 144 /* translators: %s: Private post title. */ 145 $prepend = __( 'Private: %s' ); 146 147 /** 148 * Filters the text prepended to the post title of private posts. 149 * 150 * The filter is only applied on the front end. 151 * 152 * @since 2.8.0 153 * 154 * @param string $prepend Text displayed before the post title. 155 * Default 'Private: %s'. 156 * @param WP_Post $post Current post object. 157 */ 158 $private_title_format = apply_filters( 'private_title_format', $prepend, $post ); 159 $title = sprintf( $private_title_format, $title ); 160 } 161 } 162 163 /** 164 * Filters the post title. 165 * 166 * @since 0.71 167 * 168 * @param string $title The post title. 169 * @param int $id The post ID. 170 */ 171 return apply_filters( 'the_title', $title, $id ); 172 } ?>