wpseek.com
WordPress开发者和主题制作者的搜索引擎



single_month_title › WordPress Function

Since0.71
已弃用n/a
single_month_title ( $prefix = '', $display = true )
参数: (2)
  • (string) $prefix Optional. What to display before the title.
    Required: No
    默认: (empty)
  • (bool) $display Optional. Whether to display or retrieve title. Default true.
    Required: No
    默认: true
返回:
  • (string|false|void) False if there's no valid title for the month. Title when retrieving.
定义在:
文档:

Displays or retrieves page title for post archive based on date.

Useful for when the template only needs to display the month and year, if either are available. The prefix does not automatically place a space between the prefix, so if there should be a space, the parameter value will need to have it at the end.


源码

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;
}