Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ECHO SUB-NAV
- function echo_sub_nav($postID,$forceCurrent=false){
- if($forceCurrent){
- echo '<style type="text/css">#sub_nav ul li.page-item-'.$postID.' a{color: #b30f21;}</style>';
- }
- if(is_subpage($postID)){
- $tempPost = get_post($postID);
- $subPages = wp_list_pages('title_li=&echo=0&child_of='.$tempPost->post_parent);
- }else{
- $subPages = wp_list_pages('title_li=&echo=0&child_of='.$postID);
- }
- if(!empty($subPages)){ ?>
- <nav id="sub_nav">
- <h2><?php if(is_subpage($postID)){
- echo get_the_title($tempPost->post_parent);
- }else{
- echo get_the_title($postID);
- }?></h2>
- <ul>
- <?php echo $subPages; ?>
- </ul>
- </nav>
- <?php }
- }
- // DEFINE SUB-PAGES
- function is_subpage( $postID = null, $page = null ){
- $post = get_post($postID);
- // does it have a parent?
- if ( ! isset( $post->post_parent ) || $post->post_parent <= 0 )
- return false;
- // is there something to check against?
- if ( ! isset( $page ) ) {
- // yup this is a sub-page
- return true;
- } else {
- // if $page is an integer then its a simple check
- if ( is_int( $page ) ) {
- // check
- if ( $post->post_parent == $page )
- return true;
- } else if ( is_string( $page ) ) {
- // get ancestors
- $parent = get_ancestors( $post->ID, 'page' );
- // does it have ancestors?
- if ( empty( $parent ) )
- return false;
- // get the first ancestor
- $parent = get_post( $parent[0] );
- // compare the post_name
- if ( $parent->post_name == $page )
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement