I'm presently while using code below to connect to previous and then pages

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'=> '<a href="'.get_permalink($siblings[$ID-1]->ID).'">'.get_the_title($siblings[$ID-1]->ID).'</a>','after'=> '<a href="'.get_permalink($siblings[$ID+1]->ID).'">'.get_the_title($siblings[$ID+1]->ID).'</a>');

if ($link == 'before' || $link == 'after') { echo $closest[$link]; } else { return $closest; }

after which this for that links

<?php siblings('before'); ?>                    
<?php siblings('after'); ?>

it really works great apart form when you are getting towards the finish it stops. I'd Link the very first element towards the last and also the last to the first one to form a continous loop. How do i accomplish this?



Also I must thank addedlovely with this answer

and also the user Jack for that original solution