Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //if the post has a parent
- if($post->post_parent){
- //collect ancestor pages
- $relations = get_post_ancestors($post->ID);
- //get child pages
- $result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'" );
- if ($result){
- foreach($result as $pageID){
- array_push($relations, $pageID->ID);
- }
- }
- //add current post to pages
- array_push($relations, $post->ID);
- //get comma delimited list of children and parents and self
- $relations_string = implode(",",$relations);
- //use include to list only the collected pages.
- $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
- }else {
- // display only main level and children
- $sidelinks = wp_list_pages("title_li=&echo=0&depth=3&child_of=".$post->ID);
- }
- if ($sidelinks) { ?>
- <ul class="left-nav">
- <li><a class="stand-alone" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
- <?php //links in <li> tags
- echo $sidelinks; ?>
- </ul>
- <?php }
- else { ?>
- <ul class="left-nav">
- <li><a class="stand-alone" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
- </ul>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement