Advertisement
Guest User

Untitled

a guest
Sep 9th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. // in your functions.php file add this function
  2.  
  3. function neighbors($link) {
  4.     global $post;
  5.     $neighbors = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
  6.     foreach ($neighbors as $key=>$neighbor){
  7.         if ($post->ID == $neighbor->ID){
  8.             $ID = $key;
  9.         }
  10.     }
  11.     $closest = array('before'=>get_permalink($neighbors[$ID-1]->ID),'after'=>get_permalink($neighbors[$ID+1]->ID));
  12.  
  13.     if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }
  14. }
  15.  
  16. //in your template do this
  17.  
  18. <?php neighbors('before'); ?>
  19. <?php neighbors('after'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement