Advertisement
alchymyth

page siblings navi

May 7th, 2011
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. first part - into functions.php
  2.  
  3. function siblings($link) {
  4.     global $post;
  5.     $siblings = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
  6.     foreach ($siblings as $key=>$sibling){
  7.         if ($post->ID == $sibling->ID){
  8.             $ID = $key;
  9.         }
  10.     }
  11. $number = count($siblings);
  12. $before_url = ($ID == 0) ? '' : get_permalink($siblings[$ID-1]->ID);
  13. $after_url = ($ID == $number-1) ? '' : get_permalink($siblings[$ID+1]->ID);
  14.  
  15.     $closest = array('before'=>$before_url,'after'=>$after_url,'current'=>$ID+1,'total'=>$number);
  16.  
  17.     if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }
  18. }
  19.  
  20. second part - for page.php
  21.  
  22. <?php $siblings = siblings(''); if( $siblings ) : ?>
  23. <?php if( $siblings['before'] ) { ?>
  24. <a href="<?php echo $siblings['before']; ?>">Previous </a>
  25. <?php } else {
  26. echo 'Previous '; } ?>
  27. <?php echo $siblings['current'].'/'.$siblings['total']; ?>
  28. <?php if( $siblings['after'] ) { ?>
  29. <a href="<?php siblings('after'); ?>"> Next</a>
  30. <?php } else { echo ' Next'; }
  31. endif;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement