Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created July 25, 2024 10:54
Show Gist options
  • Save andrasguseo/3e8319f461bb2b6ebfee33b227b93980 to your computer and use it in GitHub Desktop.
Save andrasguseo/3e8319f461bb2b6ebfee33b227b93980 to your computer and use it in GitHub Desktop.
TEC > Template overrides for the month view to include all events in the "Month view events per day" setting.
<?php
/**
* View: Month View - Calendar Events
*
* This is an override for the following template:
* wp-content/plugins/the-events-calendar/src/views/v2/month/calendar-body/day/calendar-events.php
*
* Override this template in your own theme by creating a file at:
* wp-content/themes/[your-theme]/tribe/events/v2/month/calendar-body/day/calendar-events.php
*
* See more documentation about our views templating system.
*
* @link http://evnt.is/1aiy
*
* @version 4.9.8
*
* @var array $day_events An array of the day event post objects. Each event is a `WP_Post` instance with additional
* properties as set from the `tribe_get_event` function.
* @var array $number_of_multiday_events The number of multi-day events.
*
* @see tribe_get_event() For the format of each event object.
*/
// Bail if there are no events for day.
if ( empty ( $day_events ) ) {
return;
}
// New part to calculate how many multi-day events are there.
$month_limit = tribe_context()->get( 'month_posts_per_page', 12 );
$remains = $month_limit - $number_of_multiday_events;
// End new part
?>
<?php foreach ( $day_events as $event ) : ?>
<?php
// New part for counting
if ( $remains <= 0 ) {
break;
}
// End new part
?>
<?php $this->setup_postdata( $event ); ?>
<?php
$this->template( 'month/calendar-body/day/calendar-events/calendar-event', [ 'event' => $event ] );
// New line, decrease remaining
$remains --;
?>
<?php endforeach; ?>
<?php
/**
* View: Month View - Day cell
*
* This is an override for the following template:
* wp-content/plugins/the-events-calendar/src/views/v2/month/calendar-body/day/cell.php
*
* Copy this template to your own theme by creating a file at:
* wp-content/themes/[your-theme]/tribe/events/v2/month/calendar-body/day/cell.php
*
* See more documentation about our views templating system.
*
* @link http://evnt.is/1aiy
*
* @version 5.3.0
*
* @var string $today_date Today's date in the `Y-m-d` format.
* @var string $day_date The current day date, in the `Y-m-d` format.
* @var array $day The current day data.{
* @type string $date The day date, in the `Y-m-d` format.
* @type bool $is_start_of_week Whether the current day is the first day of the week or not.
* @type string $year_number The day year number, e.g. `2019`.
* @type string $month_number The day year number, e.g. `6` for June.
* @type string $day_number The day number in the month with leading 0, e.g. `11` for June 11th.
* @type string $day_url The day url, e.g. `http://yoursite.com/events/2019-06-11/`.
* @type int $found_events The total number of events in the day including the ones not fetched due to the per
* page limit, including the multi-day ones.
* @type int $more_events The number of events not showing in the day.
* @type array $events The non multi-day events on this day. The format of each event is the one returned by
* the `tribe_get_event` function. Does not include the below events.
* @type array $featured_events The featured events on this day. The format of each event is the one returned
* by the `tribe_get_event` function.
* @type array $multiday_events The stack of multi-day events on this day. The stack is a mix of event post
* objects, the format is the one returned from the `tribe_get_event` function, and
* spacers. Spacers are falsy values indicating an empty space in the multi-day stack for
* the day
* }
*/
$day_id = 'tribe-events-calendar-day-' . $day_date;
$month_limit = tribe_context()->get( 'month_posts_per_page', 12 );
$more = $day['found_events'] - $month_limit;
$day['more_events'] = max( $more, 0 );
?>
<div
id="<?php echo esc_attr( $day_id ); ?>"
class="tribe-events-calendar-month__day-cell tribe-events-calendar-month__day-cell--desktop tribe-common-a11y-hidden"
>
<?php $this->template( 'month/calendar-body/day/cell-title', [ 'day' => $day, ] ); ?>
<div class="tribe-events-calendar-month__events">
<?php $this->template( 'month/calendar-body/day/multiday-events', [
'day_date' => $day['date'],
'multiday_events' => $day['multiday_events'],
'is_start_of_week' => $day['is_start_of_week'],
] ); ?>
<?php
// Modified part to add multi-day events
$this->template(
'month/calendar-body/day/calendar-events', [
'day_events' => $day['events'],
'number_of_multiday_events' => count( $day['multiday_events'] ),
]
);
?>
</div>
<?php
// Modified part to recalculate "more events"
$this->template( 'month/calendar-body/day/more-events', [
'more_events' => $day['more_events'],
'more_url' => $day['day_url'],
] );
?>
</div>
<?php
/**
* View: Month View - Multiday Events
*
* This is an override for the following template:
* wp-content/plugins/the-events-calendar/src/views/v2/month/calendar-body/day/multiday-events.php
*
* Override this template in your own theme by creating a file at:
* wp-content/themes/[your-theme]/tribe/events/v2/month/calendar-body/day/multiday-events.php
*
* See more documentation about our views templating system.
*
* @link http://evnt.is/1aiy
*
* @version 4.9.4
*
* @var string $day_date The `Y-m-d` date of the day currently being displayed.
* @var array $multiday_events An array representing the day "stack" of multi-day events. The stack is composed of
* events post objects (instances of the the `WP_Post` class with additional properties)
* and spacer indicators.
* The stack is pre-calculated for the day, events and spacers are in the correct order.
* @var bool $is_start_of_week Whether the current day is the first day in the week or not.
*
* @see tribe_get_event() For the format of the event object and its properties.
*/
if ( 0 === count( $multiday_events ) ) {
return;
}
$remains = tribe_context()->get( 'month_posts_per_page', 12 );
?>
<?php foreach ( $multiday_events as $event ) : ?>
<?php
// New part for counting
if ( $remains <= 0 ) {
break;
}
// End new part
// If we receive a falsy value, then we need to add a spacer in the "stack".
if ( false === $event ) {
$this->template( 'month/calendar-body/day/multiday-events/multiday-event-spacer' );
continue;
}
$this->setup_postdata( $event );
$this->template( 'month/calendar-body/day/multiday-events/multiday-event', [
'day_date' => $day_date,
'event' => $event,
'is_start_of_week' => $is_start_of_week,
] );
// New line, decrease remaining
$remains--;
?>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment