-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-dtree-pge.php
More file actions
42 lines (41 loc) · 1.44 KB
/
wp-dtree-pge.php
File metadata and controls
42 lines (41 loc) · 1.44 KB
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
<?php
function wpdt_get_pages_nodelist($args){
extract($args, EXTR_SKIP);
$idcount = 1;
$pageresults = &get_pages(array(
'child_of' => $child_of,
'parent' => $parent,
'sort_order' => $sort_order,
'sort_column' => $sort_column,
'hierarchical' => $hierarchical,
'exclude_tree' => $exclude_tree,
'exclude' => $exclude,
'include' => $include,
'meta_key' => $meta_key,
'meta_value' => $meta_value,
'authors' => $authors
));
$has_root_connection = false;
$nodedata = array();
if($pageresults){
foreach($pageresults as $pageresult){
$nodedata[$idcount] = array( 'id' => $pageresult->ID, 'pid' => $pageresult->post_parent, 'url' => esc_url(get_permalink($pageresult->ID)), 'name' => strip_tags(apply_filters('the_title', $pageresult->post_title)), 'title' => '');
if($pageresult->post_parent == 0){$has_root_connection = true;}
$idcount++;
}
//pages can be arranged arbitrarily, and with some creative exlusion/inclusion, you'll easily create a tree without a single page connecting to root or a even parent.
//thus this step to fixup any orphans.
foreach($nodedata as $key => $node){
if($node['pid'] == 0){continue;} //connected to root.
$hasparent = false;
foreach($nodedata as $potential_parent){
if($potential_parent['id'] == $node['pid']){
$hasparent = true; break;
}
}
if(!$hasparent){$nodedata[$key]['pid'] = 0;} //connect orphans to root.
}
}
return $nodedata;
}
?>