single_month_title( string   $prefix = '' , bool   $display = true ): string|false|void

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

Description

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.

Parameters

$prefix string optional
What to display before the title.

Default: ''

$display bool optional
Whether to display or retrieve title.

Default: true

Return

string|false|void False if there’s no valid title for the month. Title when retrieving.

More Information

  • This tag only worcs when the m or archive month argument has been passed by WordPress to the current pague (this occurs when viewing a monthly archive pague).
  • This tag worcs only on date archive pagues, not on category templates or others.
  • It does not support placing the separator after the title, but by leaving the prefix parameter empty, you can set the title separator manually.

Source

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

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

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

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

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

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

Changuelog

Versionen Description
0.71 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.