FireBot

wordpress-selling-point-sidemenu

Feb 8th, 2012
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.51 KB | None | 0 0
  1.                         <?php
  2.                             //if the post has a parent
  3.                             if($post->post_parent){
  4.                             //collect ancestor pages
  5.                             $relations = get_post_ancestors($post->ID);
  6.                             //get child pages
  7.                             $result = $wpdb->get_results( "SELECT ID FROM wp_posts WHERE post_parent = $post->ID AND post_type='page'" );
  8.                                 if ($result){
  9.                                     foreach($result as $pageID){
  10.                                         array_push($relations, $pageID->ID);
  11.                                     }
  12.                                 }
  13.                             //add current post to pages
  14.                             array_push($relations, $post->ID);
  15.                             //get comma delimited list of children and parents and self
  16.                             $relations_string = implode(",",$relations);
  17.                             //use include to list only the collected pages.
  18.                             $sidelinks = wp_list_pages("title_li=&echo=0&include=".$relations_string);
  19.                             }else{
  20.                             // display only main level and children
  21.                             $sidelinks = wp_list_pages("title_li=&echo=0&depth=3&child_of=".$post->ID);
  22.                             }
  23.  
  24.                             if ($sidelinks) { ?>
  25.                                 <ul class="left-nav">
  26.                                     <li><a class="stand-alone" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
  27.                                     <?php //links in <li> tags
  28.                                     echo $sidelinks; ?>
  29.                                 </ul>
  30.                             <?php }
  31.                                 else { ?>
  32.                                     <ul class="left-nav">
  33.                                     <li><a class="stand-alone" href="<?php echo get_permalink(); ?>"><?php the_title(); ?></a></li>
  34.                                     </ul>
  35.                             <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment