06.06.2012

Once in a while, I get issues with the WordPress’ built in functions previous_post_link() and next_post_link() where they don’t work and return nothing at all. Why doesn’t it work?

While I try to ponder the answer to that question at another time, I found a great workaround that replaces the previous_post_link() and next_post_link() using the get_permalink() function:

[crayon title=”Next and Previous Posts”]

<span class=”alignleft”>
<?php
$prevlink = get_permalink(get_adjacent_post(false,”,true));
if ($prevlink != get_permalink()){
//So navigation is not displayed when there are no previous links ?>
<a href=”<?php echo $prevlink; ?>”>< Previous post </a> <?php } ?>
</span>

<span class=”alignright”>
<?php
$nextlink = get_permalink(get_adjacent_post(false,”,false));
if ($nextlink != get_permalink()){ ?>
<a href=”<?php echo $nextlink; ?>”> Next post > </a> <?php } ?>
</span>

[/crayon]

Hope this bit of code helps!

One thought on “Previous and Next Post Links

  1. I have a suggestion. I like the plugin. I just updated your plugin. I am using your plugin on a dark gray background. Is there a way to have all the text be changed using the style sheet? I have had to change your code to get the text to be the right color and then when I updated I had to do it all over again and find the right places.

    I have another suggestion, when a user presses “Get Directions” is there a way that the original user input for “Enter location” be put into the Google “A” box?

Leave a Reply

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