HOWTO: Get link of previous and Next post in Category
-
I wanted to have a separator between the next post and previous posts link. But when there is no next or previous post the separator would still show up, lame. get_adjacent_post doesn’t work as well as it should be, needs to get fixed! Anyways, here is how i figured it out below
<?php $current = get_permalink(); $prevPost = get_previous_post(true); $prevURL = get_permalink($prevPost->ID); $nextPost = get_next_post(true); $nextURL = get_permalink($nextPost->ID); if ($current != $prevURL) { echo "<a href='$prevURL'>Previous</a>"; } if ($current != $nextURL) { echo "<a href='$nextURL'>Next</a>"; } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘HOWTO: Get link of previous and Next post in Category’ is closed to new replies.