get adjacent post wordpress code example

Example 1: get_adjacent_post wordpress

$prev_post = get_adjacent_post();
if( $prev_post )
	echo '<a href="'. get_permalink($prev_post->ID) .'">'. $prev_post->post_title .'</a>';

Example 2: get_adjacent_post wordpress

<?php
$prev = mod_get_adjacent_post('prev', array('post', 'custom1', 'custom2'));
$next = mod_get_adjacent_post('next', array('post', 'custom1', 'custom2'));
?>

<?php if($prev) : ?>
    <a href="<?php echo get_permalink($prev->ID)?>">« Go back in time</a>
<?php endif; ?>

<?php if($next) : ?>
    <a href="<?php echo get_permalink($next->ID)?>">Next: <?php echo $next->post_title; ?> »</a>
<?php endif; ?>

Tags:

Php Example