Pop the following code into your functions.php file in your active theme directory:
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;
}
}
$closest = array('before'=>get_permalink($siblings[$ID-1]->ID),'after'=>get_permalink($siblings[$ID+1]->ID));
if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }
}
To call the function:
<?php siblings('before'); ?>
or
<?php siblings('after'); ?>
and it will echo out the link to the previous or next page.
If you want both you can leave the function empty and it will return an array with both links.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…