Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- first part - into functions.php
- function siblings($link) {
- global $post;
- $siblings = get_pages('child_of='.$post->post_parent.'&parent='.$post->post_parent);
- foreach ($siblings as $key=>$sibling){
- if ($post->ID == $sibling->ID){
- $ID = $key;
- }
- }
- $number = count($siblings);
- $before_url = ($ID == 0) ? '' : get_permalink($siblings[$ID-1]->ID);
- $after_url = ($ID == $number-1) ? '' : get_permalink($siblings[$ID+1]->ID);
- $closest = array('before'=>$before_url,'after'=>$after_url,'current'=>$ID+1,'total'=>$number);
- if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }
- }
- second part - for page.php
- <?php $siblings = siblings(''); if( $siblings ) : ?>
- <?php if( $siblings['before'] ) { ?>
- <a href="<?php echo $siblings['before']; ?>">Previous </a>
- <?php } else {
- echo 'Previous '; } ?>
- <?php echo $siblings['current'].'/'.$siblings['total']; ?>
- <?php if( $siblings['after'] ) { ?>
- <a href="<?php siblings('after'); ?>"> Next</a>
- <?php } else { echo ' Next'; }
- endif;?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement