Created
December 26, 2012 16:39
-
-
Save anonymous/4381327 to your computer and use it in GitHub Desktop.
We're using TEC on an Austrian traditional costume club <a href="http://goldhauben.neuhofen-ybbs.at/">website</a> both for announcing upcoming events and for tracking past ones in some sort of chronicle. To that end, I've hacked TEC v2.0.10 a bit to be able to have URLs like http://goldhauben.neuhofen-ybbs.at/events/2011/ that yield a descending…
This file contains hidden or 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
diff --recursive -u the-events-calendar-orig/lib/the-events-calendar.class.php the-events-calendar/lib/the-events-calendar.class.php | |
--- the-events-calendar-orig/lib/the-events-calendar.class.php 2012-12-11 00:35:12.000000000 +0100 | |
+++ the-events-calendar/lib/the-events-calendar.class.php 2012-12-26 16:53:00.000000000 +0100 | |
@@ -1461,6 +1461,7 @@ | |
$newRules[$base . $upcoming] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=upcoming'; | |
$newRules[$base . $past . '/page/(\d+)'] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=past&paged=' . $wp_rewrite->preg_index(1); | |
$newRules[$base . $past] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=past'; | |
+ $newRules[$base . '(\d{4})$'] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=year' .'&eventDate=' . $wp_rewrite->preg_index(1); | |
$newRules[$base . '(\d{4}-\d{2})$'] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=month' .'&eventDate=' . $wp_rewrite->preg_index(1); | |
$newRules[$base . '(\d{4}-\d{2}-\d{2})$'] = 'index.php?post_type=' . self::POSTTYPE . '&eventDisplay=day' .'&eventDate=' . $wp_rewrite->preg_index(1); | |
$newRules[$base . 'feed/?$'] = 'index.php?eventDisplay=upcoming&post_type=' . self::POSTTYPE . '&feed=rss2'; | |
@@ -2455,6 +2456,27 @@ | |
} | |
/** | |
+ * Given a date (YYYY-MM-DD), returns the first of the next year | |
+ * | |
+ * @param date | |
+ * @return date | |
+ */ | |
+ public function nextYear( $date ) { | |
+ $dateParts = split( '-', $date ); | |
+ return ++$dateParts[0] . '-01-01'; | |
+ } | |
+ /** | |
+ * Given a date (YYYY-MM-DD), return the last day of the previous year | |
+ * | |
+ * @param date | |
+ * @return date | |
+ */ | |
+ public function previousYear( $date ) { | |
+ $dateParts = split( '-', $date ); | |
+ return --$dateParts[0] . '-12-31'; | |
+ } | |
+ | |
+ /** | |
* Callback for adding the Meta box to the admin page | |
* @return void | |
*/ | |
@@ -2871,4 +2893,4 @@ | |
} // end TribeEvents class | |
-} // end if !class_exists TribeEvents | |
\ Kein Zeilenumbruch am Dateiende. | |
+} // end if !class_exists TribeEvents | |
diff --recursive -u the-events-calendar-orig/lib/tribe-event-query.class.php the-events-calendar/lib/tribe-event-query.class.php | |
--- the-events-calendar-orig/lib/tribe-event-query.class.php 2012-12-11 00:35:12.000000000 +0100 | |
+++ the-events-calendar/lib/tribe-event-query.class.php 2012-12-26 16:51:43.000000000 +0100 | |
@@ -84,6 +84,9 @@ | |
break; | |
case "month": | |
$query = self::setMonthDisplayTypeArgs($query); | |
+ break; | |
+ case "year": | |
+ $query = self::setYearDisplayTypeArgs($query); | |
} | |
} else if ( is_single() ) { | |
$args = &$query->query_vars; | |
@@ -186,6 +189,27 @@ | |
return $query; | |
} | |
+ | |
+ // year functions | |
+ public static function setYearDisplayTypeArgs($query) { | |
+ global $wp_query; | |
+ $tribe_ecp = TribeEvents::instance(); | |
+ $args = &$query->query_vars; | |
+ | |
+ $args['posts_per_page'] = -1; // show ALL month posts | |
+ $args['start_date'] = date_i18n( TribeDateUtils::DBDATEFORMAT ); | |
+ $args['start_date'] = substr_replace( $args['start_date'], '01-01', -5 ); | |
+ | |
+ if ( isset ( $wp_query->query_vars['eventDate'] ) ) | |
+ $args['start_date'] = $wp_query->query_vars['eventDate'] . "-01-01"; | |
+ | |
+ $args['eventDate'] = $args['start_date']; | |
+ $args['end_date'] = date( 'Y-m-d', strtotime( $tribe_ecp->nextYear($args['start_date']) ) -(24*3600) ); | |
+ $args['orderby'] = 'event_date'; | |
+ $args['order'] = "DESC"; | |
+ | |
+ return $query; | |
+ } | |
public static function addEventConditions($where, $cur_query) { | |
global $wpdb; | |
diff --recursive -u the-events-calendar-orig/lib/tribe-templates.class.php the-events-calendar/lib/tribe-templates.class.php | |
--- the-events-calendar-orig/lib/tribe-templates.class.php 2012-12-11 00:35:12.000000000 +0100 | |
+++ the-events-calendar/lib/tribe-templates.class.php 2012-12-26 16:06:26.000000000 +0100 | |
@@ -106,7 +106,7 @@ | |
$template = TribeEventsTemplates::getTemplateHierarchy('single'); | |
} | |
// list view | |
- elseif ( tribe_is_upcoming() || tribe_is_past() || tribe_is_day() || (is_single() && tribe_is_showing_all()) ) { | |
+ elseif ( tribe_is_upcoming() || tribe_is_past() || tribe_is_day() || tribe_is_year() || (is_single() && tribe_is_showing_all()) ) { | |
$template = TribeEventsTemplates::getTemplateHierarchy('list'); | |
} | |
// grid view | |
diff --recursive -u the-events-calendar-orig/public/template-tags/loop.php the-events-calendar/public/template-tags/loop.php | |
--- the-events-calendar-orig/public/template-tags/loop.php 2012-12-11 00:35:12.000000000 +0100 | |
+++ the-events-calendar/public/template-tags/loop.php 2012-12-26 16:04:52.000000000 +0100 | |
@@ -50,6 +50,18 @@ | |
return ($tribe_ecp->displaying == 'day') ? true : false; | |
} | |
+ /** | |
+ * Single Year Test | |
+ * | |
+ * Returns true if the query is set for single year, false otherwise | |
+ * | |
+ * @return bool | |
+ * @since 2.0 | |
+ */ | |
+ function tribe_is_year() { | |
+ $tribe_ecp = TribeEvents::instance(); | |
+ return ($tribe_ecp->displaying == 'year') ? true : false; | |
+ } | |
/** | |
* Past Loop View Test | |
@@ -175,4 +187,4 @@ | |
} | |
} | |
-?> | |
\ Kein Zeilenumbruch am Dateiende. | |
+?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment