Last active
May 31, 2021 16:38
-
-
Save leavlzi/52e66c2215dd51354b6956edc1606e70 to your computer and use it in GitHub Desktop.
Custom the_post_navigation at Wordpress from https://stackoverflow.com/questions/43999014/changing-a-next-previous-link-to-display-post-title
Thanks, great snippet.
Here is my slight alteration:
<?php
$prev_post = get_previous_post();
$prev_id = $prev_post->ID;
$prev_permalink = get_permalink($prev_id);
$next_post = get_next_post();
$next_id = $next_post->ID;
$next_permalink = get_permalink($next_id);
?>
<aside class="container">
<nav class="row">
<div class="col-6 text-left">
<div class="previous-timeline">
<a href="<?php echo $prev_permalink; ?>" rel="prev">
<span class="meta-nav">←</span> Previous
<h5><?php echo $prev_post->post_title; ?></h5>
</a>
</div>
</div>
<div class="col-6 text-right">
<div class="next-timeline">
<a href="<?php echo $next_permalink; ?>">
Next <span class="meta-nav">→</span>
<h5><?php echo $next_post->post_title; ?></h5>
</a>
</div>
</div>
</nav>
</aside>
Updated the variables for consistancy
Wrapped the Next and Title in a single
THANK YOU, GREAT CODE FOR ME
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Thank you for the snippet. There seems to be one slight hiccup with this.
The $permalink on the next post will override the $permalink from the previous post since they're using the same variable name. I just renamed them to:
$next_permalink = get_permalink($nid);
$prev_permalink = get_permalink($id);
and use the new variables when echoing them out.
Other than that, everything should work. ( ´ ▽ ` )b