Created
September 10, 2012 02:12
-
-
Save PaulHughes01/3688451 to your computer and use it in GitHub Desktop.
New Views/Templating Design Example
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
| <?php | |
| /** | |
| * The abstracted view of a single event. | |
| * This view contains the hooks and filters required to create an effective single event view. | |
| * | |
| * You can recreate and ENTIRELY new single view (that does not utilize these hooks and filters) | |
| * by doing a template override, and placing a single-event.php file in a /tribe-events/ directory within your theme directory, which will override the /views/single-event.php. | |
| */ | |
| ?> | |
| <?php | |
| // This file is the /views/single-event.php file. | |
| /** | |
| * The file should contain all apply_filters that generate the page's content. | |
| */ | |
| apply_filters( 'tribe_tec_before_event_single_page', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_before_event_title', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_the_event_title', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_after_the_event_title', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_before_event_meta', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_the_event_meta', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_after_event_meta', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_before_event_content', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_the_event_content', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_after_event_content', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_before_event_pagination', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_the_event_pagination', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_after_event_pagination', '', get_the_ID() ); | |
| apply_filters( 'tribe_tec_after_event_single_page', '', get_the_ID() ); | |
| ?> | |
| <?php | |
| // This file is the /views/hooks/single-event.php file, which contains all the add_filters necessary | |
| // with the proper markup in their callbacks to generate the content. | |
| class Tribe_Events_Default_Single_Event_Template { | |
| function init() { | |
| add_filter( 'tribe_tec_before_event_single_page', array( __CLASS__, 'before_single_page' ), 1, 1 ); | |
| add_filter( 'tribe_tec_before_event_title', array( __CLASS__, 'before_event_title' ), 1, 1 ); | |
| add_filter( 'tribe_tec_the_event_title', array( __CLASS__, 'the_event_title' ), 1, 1 ); | |
| add_filter( 'tribe_tec_after_the_event_title', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_before_event_meta', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_the_event_meta', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_after_event_meta', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_before_event_content', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_the_event_content', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_after_event_content', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_before_event_pagination', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_the_event_pagination', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_after_event_pagination', array( __CLASS__, ' ' ), 1, 1 ); | |
| add_filter( 'tribe_tec_after_event_single_page', array( __CLASS__, ' ' ), 1, 1 ); | |
| } | |
| function before_single_page( $event_id ) { | |
| return '<h3>This is the page for event ' . $event_id . '</h3>'; | |
| } | |
| function before_event_title( $event_id ) { | |
| return '<i>This comes before the event title.</i>'; | |
| } | |
| function the_event_title( $event_id ) { | |
| $title = '<h1>'; | |
| $title .= get_the_title( $event_id ); | |
| $title .= '</h1>'; | |
| return $title; | |
| } | |
| function after_event_title( $event_id ) { | |
| return '<i>This comes after the event title.</i>'; | |
| } | |
| // etc. | |
| // etc. | |
| // etc. | |
| } | |
| Tribe_Events_Default_Single_Event_Template::init(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment