Snippi
A super awesome snippet tool.
- 1.
<?php function wpdev_156446_list_parent_page_tree() {
- 2.
- 3.
if ( ! is_page() ) {
- 4.
return;
- 5.
}
- 6.
//parent variables
- 7.
$parent = get_post($post->post_parent);
- 8.
$parent_title = get_the_title($parent);
- 9.
$grandparent = $parent->post_parent;
- 10.
$grandparent_title = get_the_title($grandparent);
- 11.
$current_page_parent = ( $post->post_parent ? $post->post_parent : $post->ID );
- 12.
- 13.
// is the homepage the granparent? = third level page
- 14.
if ($grandparent == is_page('0')) {
- 15.
$children = wp_list_pages("title_li=&include=".$post->post_parent."&echo=0"); // list the parent page
- 16.
$children .= wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); // append the list of children pages to the same $children variable
- 17.
if ($children) { ?>
- 18.
<ul class="submenu">
- 19.
echo $children; /*print list of pages*/
- 20.
</ul>
- 21.
- 22.
// is the homepage the parent? = second level page
- 23.
} elseif ($post->post_parent ==is_page('0')) {
- 24.
$children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
- 25.
if ($children) {
- 26.
- 27.
<ul>
- 28.
<li class="current_page_item"><?php echo get_the_title(); ?></li>
- 29.
echo $children;
- 30.
</ul>
- 31.
- 32.
} else {// your else stuff
- 33.
- 34.
}
- 35.
- 36.
- 37.
} ?>
- 38.