-
-
Save theeventscalendar/f56b587a7203a87ee53a to your computer and use it in GitHub Desktop.
Let visitors page through all months (not just the populated date range)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Allows visitors to page forward/backwards in any direction within month view | |
* an "infinite" number of times (ie, outwith the populated range of months). | |
*/ | |
class ContinualMonthViewPagination { | |
protected $tec; | |
public function __construct() { | |
add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) ); | |
add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) ); | |
} | |
public function next_month() { | |
$url = tribe_get_next_month_link(); | |
$text = tribe_get_next_month_text(); | |
$date = $this->tec()->nextMonth( tribe_get_month_view_date() ); | |
return '<a data-month="' . $date . '" href="' . $url . '" rel="next">' . $text . ' <span>»</span></a>'; | |
} | |
public function previous_month() { | |
$url = tribe_get_previous_month_link(); | |
$text = tribe_get_previous_month_text(); | |
$date = $this->tec()->previousMonth( tribe_get_month_view_date() ); | |
return '<a data-month="' . $date . '" href="' . $url . '" rel="prev"><span>«</span> ' . $text . ' </a>'; | |
} | |
/** | |
* Can be simplified in future, but for the moment means this snippet | |
* should work with 3.10+ as well as older versions of TEC. | |
* | |
* @return Tribe__Events__Events | |
*/ | |
protected function tec() { | |
if ( ! isset( $this->tec ) ) { | |
if ( class_exists( 'Tribe__Events__Events' ) ) $this->tec = Tribe__Events__Events::instance(); | |
elseif ( class_exists( 'TribeEvents' ) ) $this->tec = TribeEvents::instance(); | |
} | |
return $this->tec; | |
} | |
} | |
new ContinualMonthViewPagination; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment