FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
wp-template-controller/example-controller.php at master · creativecoder/wp-template-controller · GitHub
creativecoder
/
wp-template-controller
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
wp-template-controller
/
example-controller.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (28 loc) · 1.12 KB
Breadcrumbs
wp-template-controller
/
example-controller.php
Copy path
File metadata and controls
34 lines (28 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
();
Back
|
FazBrowse Home
|
New Git URL