
Description:
get_adjacent_post – A WordPress function to retrieve previous or next post. It is mostly useful if you want to integrate go to next/previous post button in your WordPress theme.
Parameters:
$in_same_cat(optional)(boolean) – If you want to retrieve next/previous post from same category
$excluded_categories (optional)(string) – String of comma-separated category ids
$previous(optional)(boolean) – If you want to retrieve previous post
Basic usage examples:
<?php $previousPost = get_adjacent_post(true, "", true)); $nextPost = get_adjacent_post(true); ?> <?php if($previousPost) : ?> <a href="<?php echo get_permalink($previousPost->ID)?>">« Previous post</a> <?php endif; ?> <?php if($nextPost) : ?> <a href="<?php echo get_permalink($nextPost->ID)?>">Next: <?php echo $next->post_title; ?> »</a> <?php endif; ?>
Leave a Reply