Reputation: 1509
How to create previous/next links for posts with the same parent post (not category)?
similar to this:
$previous_post = get_adjacent_post( true, '', true);
but for posts with the same parent.
Upvotes: 0
Views: 1383
Reputation: 3648
I presume your'e talking about pages.
so you would need to declare the parent then use get_pages to call the other pages.
so in your loop:
<?php $parent = $post->post_parent; $pagelist = get_pages('post_type=page&sort_column=menu_order&sort_order=desc&child_of='.$parent); $pages = array(); foreach ($pagelist as $page) {$pages[] += $page->ID;}
$current = array_search($post->ID, $pages);
$prevID = $pages[$current-1];
$nextID = $pages[$current+1];
?>
<?php if (!empty($prevID)) { ?>
<a href="<?php echo get_permalink($prevID); ?>" title="<?php echo get_the_title($prevID); ?>"><?php echo get_the_title($prevID); ?></a>
<?php }
if (!empty($nextID)) { ?>
<a href="<?php echo get_permalink($nextID); ?>" title="<?php echo get_the_title($nextID); ?>"><?php echo get_the_title($nextID); ?></a>
<?php } ?>
Upvotes: 4