Skip to content

Instantly share code, notes, and snippets.

@annelyse
Last active September 28, 2021 17:35
Show Gist options
  • Save annelyse/b3d6aad5d2aa14ec6ce8a8c8de5fa26e to your computer and use it in GitHub Desktop.
Save annelyse/b3d6aad5d2aa14ec6ce8a8c8de5fa26e to your computer and use it in GitHub Desktop.
<?php if (!empty($post->post_parent)) {
$pagelist = get_pages("child_of=" . $post->post_parent . "&sort_column=menu_order&sort_order=asc&exclude=" . $post->ID);
$page_array = array();
foreach ($pagelist as $item) {
$page_array[] += $item->ID;
}
if (!empty($page_array)) {
if (count($page_array) >= 2) {
$prevID = $page_array[0];
$nextID = $page_array[1];
} else {
$prevID = $post->ID;
$nextID = $page_array[0];
}
}
?>
<div class="navigation-pages">
<a class="<?php if ($prevID == $post->ID) echo "disabled"; ?>" href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">
<?= get_the_title($prevID); ?></a>
<a class="<?php if ($nextID == $post->ID) echo "disabled"; ?>" href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"><?= get_the_title($nextID); ?></a>
</div>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment