How can I get a Previous / Next navigation that only navigates the child pages of the current page?
By that i mean url.com/page/child1, url.com/page/child2 and so on..
I’ve been searching around alot but I’m still lost.
It seems like you can’t do that according to wordpress (they recommend plugins..)
All right, here it is, fully working:
<?php
$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="https://wordpress.stackexchange.com/questions/54422/<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>">Previous</a>
</div>
<?php }
if (!empty($nextID)) { ?>
<div class="Next">
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>">Next</a>
</div>
<?php } ?>
</div>
One little cosmetic thing needs to get fixed, and that is that the “Previous” and “Next” links always should be shown, whether or not there are any more pages…