Created
September 11, 2013 08:57
-
-
Save Kenshino/6521051 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*FUNCTION CODE HERE */ | |
function get_top_parent_page_id() { | |
global $post; | |
// Check if page is a child page (any level) | |
if ($post->ancestors) { | |
// Grab the ID of top-level page from the tree | |
return end($post->ancestors); | |
} else { | |
// Page is the top level, so use it's own id | |
return $post->ID; | |
} | |
} | |
function is_subpage() { | |
global $post; // load details about this page | |
if ( is_page() && $post->post_parent ) { // test to see if the page has a parent | |
return $post->post_parent; // return the ID of the parent post | |
} else { // there is no parent so ... | |
return false; // ... the answer to the question is false | |
} | |
} | |
/*TEMPLATE CODE HERE */ | |
<aside id="sidebar" class="col-right"> | |
<div class="child_page_list"> | |
<ul> | |
<?php | |
if (is_subpage()): | |
wp_list_pages('title_li=&child_of='.get_top_parent_page_id()); | |
else: | |
$children = get_children($post->ID); | |
if (empty($children)): | |
wp_list_pages('title_li=&include='.$post->ID); | |
else: | |
wp_list_pages('title_li=&child_of='.get_top_parent_page_id()); | |
endif; | |
endif; | |
?> | |
</ul> | |
</div> | |
</aside> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment