-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample-controller.php
34 lines (28 loc) · 1.12 KB
/
example-controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* Controller for template data
* - Each method in the class that matches a template name will be loaded for that template
* - Ex: `single()` will be loaded for single.php. `common()` is called for all templates
* - Within each method, use `$this->add( 'name', $data )` for each variable you'd like to pass to a template
* - Use `tpl_var('name')` or `get_tpl_var('name')` to call the data from within each template file
*
* @package WordPress
* @subpackage Template_Controller
* @uses Template_Controller Parent class for controller
*/
class My_Controller extends Template_Controller {
public function common() {
$this->add( 'hi', 'I load for every template on the site.' );
}
public function page() {
$this->add( 'yo', 'I load for page.php and custom page templates.' );
}
public function single() {
$this->add( 'whazup', 'I load for single.php, for all post types (any template that starts with "single-").' );
}
public function single_post() {
$this->add( 'dude', 'I load only for built in single post templates (aka single-post.php)' );
}
}
// Initialize controller
My_Controller::init();