side-menu.php
1.1 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
43
44
45
46
47
48
49
<?php
function show_all_children($parent_id, $post_id, $current_level)
{
$top_parents = array();
$top_parents = get_post_ancestors($post_id);
$top_parents[] = $post_id;
$children = get_posts(
array(
'post_type' => 'page'
, 'posts_per_page' => -1
, 'post_parent' => $parent_id
, 'order_by' => 'title'
, 'order' => 'ASC'
));
if (empty($children)) return;
echo '
<a class="top_parent" href="'.get_permalink($parent_id).'" title="'.get_the_title($parent_id).'">'.get_the_title($parent_id).'</a>';
echo '<ul class="side-menu children level-'.$current_level.'-children">';
foreach ($children as $child)
{
echo '<li';
if (in_array($child->ID, $top_parents))
{
echo ' class="current_page_item"';
}
echo '>';
echo '<a href="'.get_permalink($child->ID).'">';
echo apply_filters('the_title', $child->post_title);
echo '</a>';
// now call the same function for child of this child
if ($child->ID && (in_array($child->ID, $top_parents)))
{
show_all_children($child->ID, $post_id, $current_level+1);
}
echo '</li>';
}
echo '</ul>';
}