Saturday, December 31, 2022
HomeWordPress Developmentpagination - The way to paginate by means of youngster and grandchild...

pagination – The way to paginate by means of youngster and grandchild pages (present code solely works with youngster)


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?

  1. Mum or dad web page
  2. Little one 1
  3. Little one 2
  4. Grandchild (youngster of two)
  5. 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 } ?>

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments