Skip to content

Calendars

Kees Meijer edited this page Sep 9, 2017 · 3 revisions

By default the same calendar is used as displayed by the WordPress get_calendar() function.

Here is the calendar styled by the default theme Twenty Seventeen

default calendar

To display a calendar with post titles you can use the Post Type Calendar plugin together with this plugin.

If you want to link the post titles to date archives (instead of the post itself) you have to add some code to your (child) theme's functions.php.

add_filter( 'post_type_calendar_daily_html', 'use_cpt_date_archives_for_calendar', 10, 4 );

function use_cpt_date_archives_for_calendar( $html, $post, $args, $title ) {

	$archives       = isset( $args['linkto'] ) && ( 'date_archive' === $args['linkto'] );
	$post_type      = isset( $post->post_type ) ? $post->post_type : '';
	$day_link       = function_exists( 'cptda_get_day_link' );
	$is_cpt_archive = function_exists( 'cptda_is_date_post_type' );

	if ( ! ( $archives && $day_link && $is_cpt_archive && $post_type ) ) {
		return $html;
	}

	if ( cptda_is_date_post_type( $post_type ) ) {
		$date = keesiemeijer\Post_Type_Calendar\get_date_from_post( $post );
		$url = cptda_get_day_link( $date['year'], $date['month'], $date['day'], $post_type );
		$html = "<a href='{$url}'>{$title}</a>";
	}

	return $html;
}
Clone this wiki locally