Next Previous siblings child pages


I tried this piece of code : because I couldn’t figure out how to get the next and the previous post. But this code won’t work now and I’m not able to comment.

The error I get is "Undefined offset: -1" when looking for the ID.
Here is the full code found on the related page. Thanks for any help !

$pagelist = get_pages("child_of=".$post->post_parent."&parent=".$post->post_parent."&sort_column=menu_order&sort_order=asc");
$pages = array();
foreach ($pagelist as $page) {
   $pages[] += $page->ID;

$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];

<div class="navigation">
<?php if (!empty($prevID)) { ?>
<div class="previous">
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous</a>

<?php }
if (!empty($nextID)) { ?>
<div class="Next">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next</a>
<?php } ?>
sugardaddy 2 months 0 Answers 12 views 0

Leave an answer