Guys

How can I get the link and title of both next and previous post on the single page? Just like in the screenshot below.

I try to use this but nothing shows up.

$prev = get_previous_post();
$next = get_next_post();
$prev_title = $prev ? get_the_title($prev) : 'Current is First Post';
$next_title = $next ? get_the_title($next) : 'Current is Last Post';

next and previous post with link and name

Thank you so much.

4 s
4

Here’s what I did.

$previous = get_previous_post();
$next = get_next_post();

if ( get_next_post() ) { ?>
  <p><?php echo get_the_title($next) ?></p>
<?php } if ( get_previous_post() ) { ?>
  <p><?php echo get_the_title($previous) ?></p>
<?php } ?>

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *