single_month_title

函式
single_month_title ( $prefix = '', $display = true )
引數
  • (string) $prefix Optional. What to display before the title.
    Required:
    Default: (empty)
  • (bool) $display Optional. Whether to display or retrieve title. Default true.
    Required:
    Default: true
返回值
  • (string|false|void) False if there's no valid title for the month. Title when retrieving.
定義位置
相關方法
single_post_titlesingle_tag_titlesingle_cat_titlesingle_term_titleget_the_title
引入
0.71
棄用
-

single_month_title: 這個函式用來顯示單月檔案頁的標題。它需要兩個可選引數–$prefix和$display–用於為標題新增字首,並控制標題是否在螢幕上顯示或以字串形式返回。

根據日期顯示或檢索文章存檔的頁面標題。

當模板只需要顯示月份和年份(如果有的話)時很有用。字首之間不會自動放置空格,所以如果應該有空格,引數值需要在最後。

function single_month_title( $prefix = '', $display = true ) {
	global $wp_locale;

	$m        = get_query_var( 'm' );
	$year     = get_query_var( 'year' );
	$monthnum = get_query_var( 'monthnum' );

	if ( ! empty( $monthnum ) && ! empty( $year ) ) {
		$my_year  = $year;
		$my_month = $wp_locale->get_month( $monthnum );
	} elseif ( ! empty( $m ) ) {
		$my_year  = substr( $m, 0, 4 );
		$my_month = $wp_locale->get_month( substr( $m, 4, 2 ) );
	}

	if ( empty( $my_month ) ) {
		return false;
	}

	$result = $prefix . $my_month . $prefix . $my_year;

	if ( ! $display ) {
		return $result;
	}
	echo $result;
}

常見問題

FAQs
檢視更多 >