the_title() WordPress関数 テンプレートタグ

the_title()

参照:WordPress Codex-the_title()

構文

the_title($before[オプション],$after[オプション],$echo[オプション]);

 

the_title()の詳細

 動 作 

$echo=true:現在のタイトルを表示。

$echo=false:現在のタイトルを返す。

 返り値 

$echo:true タイトルを表示

$echo:false 文字列を返す

 引 数 

$before[オプション]

(文字列)タイトルの前に置くテキスト

(デフォルト)なし

$after[オプション]

(文字列)タイトルの後ろに置くテキスト。

(デフォルト)なし

$echo[オプション]

(true/false)

true タイトルを表示

false 文字列を返す

(デフォルト)true

 

※the_titleはタグで囲まない。

タイトルがない場合にタグだけが出力される。

引数でタグの設定をする。

 

the_title()のコード

参照:wp-includes/post-template.php

<?php
32	/**
33	 * Display or retrieve the current post title with optional markup.
34	 *
35	 * @since 0.71
36	 *
37	 * @param string $before Optional. Markup to prepend to the title. Default empty.
38	 * @param string $after  Optional. Markup to append to the title. Default empty.
39	 * @param bool   $echo   Optional. Whether to echo or return the title. Default true for echo.
40	 * @return string|void Current post title if $echo is false.
41	 */
42	function the_title( $before = '', $after = '', $echo = true ) {
43	        $title = get_the_title();
44	
45	        if ( strlen( $title ) == 0 ) {
46	                return;
47	        }
48	
49	        $title = $before . $title . $after;
50	
51	        if ( $echo ) {
52	                echo $title;
53	        } else {
54	                return $title;
55	        }
56	}
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	}
?>


 

WordPressのおすすめ-カスタマイズ編

おすすめ

 

スポンサードリンク

スポンサードリンク