forked from papertower/WP-Controllers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Page.php
95 lines (79 loc) · 2.08 KB
/
Page.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
class Page extends PostController {
protected static
$post_type = 'page';
protected
$_parent,
$_children;
/**
* Returns pages children, if any
* @return array
*/
public function children() {
if ( $this->_children ) return $this->_children;
$this->_children = self::get_pages(array(
'hierarchical' => false,
'parent' => $this->id,
'post_status' => 'publish,private'
));
return $this->_children;
}
/**
* Returns page parent controller, if any
* @return object|null
*/
public function parent() {
if ( $this->_parent ) return $this->_parent;
if ( $this->post->post_parent == 0 ) return;
return $this->_parent = self::get_controller($this->post->post_parent);
}
/**
* Same as standard get_pages but returns as controllers
*
* @link http://codex.wordpress.org/Function_Reference/get_pages
* @param array $args
* @return array
*/
public static function get_pages($args) {
$pages = get_pages($args);
foreach($pages as &$page)
$page = self::get_controller($page);
return $pages;
}
/**
* Returns only top-level pages
* @param array $args (optional)
*/
public static function get_base_pages($args = array()) {
$args['hierarchical'] = false;
$args['parent'] = 0;
return self::get_pages($args);
}
/**
* Returns pages of specified template(s)
* @param array|string $templates
* @param array $options (optional)
*/
public static function get_page_templates($templates, $options = array()) {
$options = array_merge_recursive($options, array(
'post_type' => 'page',
'numberposts' => -1,
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => $templates
)
)
));
return self::get_controllers($options);
}
/**
* Returns parent controller for post in loop
* @return object
*/
public static function get_parent() {
global $post;
return ( $post->post_parent ) ? self::get_controller($post->post_parent) : null;
}
}
?>