/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?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){ } } //add current post to pages //get comma delimited list of children and parents and self //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=1&child_of=".$post->ID); } if ($sidelinks) { ?> <ul id="parent"><li><?php the_title(); ?></li></ul> <ul> <?php echo $sidelinks; ?> </ul> <?php } ?>