I need to paginate youngster and grandchild pages of a father or mother web page. My code works, but it surely skips granchild pages and goes to the following youngster web page. How can I alter this code to additionally embrace grandchildren?
- Mum or dad web page
- Little one 1
- Little one 2
- Grandchild (youngster of two)
- Little one 3
On Little one 1, I need “subsequent” to go to Little one 2, and nothing as “earlier. On Little one 2 I need Grandchild to be the “subsequent.” On Grandchild, I need “subsequent” to be Little one 3 and “earlier” to be Little one 2.
<?php
$args = array(
'child_of' => $post->post_parent,
'father or mother' => $post->post_parent,
'sort_column' => 'menu_order',
);
$pagelist = get_pages($args);
$pages = array();
foreach ($pagelist as $web page) {
$pages[] += $page->ID;
}
$present = array_search($post->ID, $pages);
?>
<?php if (isset($pages[$current-1])) { ?>
<?php $prevID = $pages[$current-1]; ?>
<a href="<?php echo get_permalink($prevID); ?>">Earlier</a>
<?php }
if (isset($pages[$current+1])) { ?>
<?php $nextID = $pages[$current+1]; ?>
<a href="<?php echo get_permalink($nextID); ?>">Subsequent</a>
<?php } ?>