Almost every WordPress theme you’ll come across has support for going to the previous or next post. That’s all well and good, but in WordPress 2.9 we got the ability to have post thumbnails. Wouldn’t it be great to use thumbnails instead of or alongside our post titles? The answer is yes, it would. So I embarked on a journey to figure out how to add this functionality to your theme, and have posted the results below. First for regular WordPress users, and then for Thesis users.
-
Add post thumbnail support
Open up functions.php and place
add_theme_support(‘post-thumbnails’); in there, if it isn’t there already. -
Add the code
Open single.php and go down to where the previous_post_link and next_post_link is situated. If your theme doesn’t have that already, then just find a proper place for the thumbnails. Place the following code in:
<?php $prevPost = get_previous_post(); $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(150,150) ); previous_post_link('%link',''.$prevthumbnail.'', TRUE); ?> <p class="prev_next2"><?php previous_post_link('%link','<') ; ?> <?php $nextPost = get_next_post(); $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(150,150) ); next_post_link('%link',''.$nextthumbnail.'', TRUE); ?> <p class="prev_next2"><?php previous_post_link('%link','>') ; ?></p>And that’s it for the code. The 150,150 is the size of the thumbnail, so feel free to experiment with that. You can style the thumbnail by targetting .wp-post-image in your css. The ‘<' can be changed to ‘%title’ if you’d like to put your previous/next titles in there instead of an arrow, and this can be styled by targeting p.prev_next2.
-
Add post thumbnails to your post
Go into your post screen on the dashboard, and make sure you have an image set for “Featured image” on the right hand size. This is where the thumbnail will come from.
-
For Thesis users:
The trick works the same for Thesis, only instead of placing it in single.php, place it in a function like follows:
function prev_next(){
if (is_single()) {
?>
// CODE HERE
<?php } }
add_action('thesis_hook_after_content, 'prev_next);
remove_action('thesis_hook_after_content','thesis_prev_next_posts');
The remove_action gets rid of the previous/next navigation that is already built in.
Sources:
WordPress support forums
Digging into WordPress
Stay Updated

You'll notice this site talks about the Thesis theme for Wordpress. Don't know what the heck that is? Find out.



{ 14 comments… read them below or add one }
When you say to place the code for Thesis in a function, where exactly would that go? I’m assuming it’s not custom functions because it’s not defined as such.
Thanks for your help — great site!
Yes, that’s custom functions. All functions for Thesis go in that file.
And thanks.
Hi Matt,
Will this trick work on pages too? I use Thesis.
It will work in Thesis but it will not work on Pages. Pages don’t have a “previous” or “next”.
hey there, thanks for the info, I don’t see a single.php within my thesis theme, am I missing something?
Thanks,
Laura
maybe I should read the full post next time…
got it, Thanks,
Hello,
I am testing it but it looks like those functions are not defined?
Is there something that I am missing?
Thank you, Marie
What do you mean the functions aren’t defined?
I had the same issue, the problem was when copy & pasting “add_theme_support(‘post-thumbnails’);” you get fancy apostrophes around “post-thumbnails”. To fix it just delete the apostrophes and replace them with a normal ‘.
Thanks for the post Matt.
My issue is that i want to add next page to my post so like example
info info info…
Next Page
I want to put nextpage at the bottom of my website so if i click that it will continue to the post but it has to to hidden i dont want the topic to show above.
great, this just messed up my functions file in thesis…its doesnt work, sir!
Thanks for this, but I did have to do some cleaning up to make it work.
First, you need to add a closing to the first previous link.
Second, I said the first previous link, because you have two of them.
Third, need to change the thumbnail from ‘true’ to ‘false’ to have it work correctly. Doesn’t show up some times, if you don’t.
Fourth, obviously need to change the ‘second’ previous link to ‘next_post_link’.
Here it is, all cleaned up. No need for ‘styling’ just cut and paste:
“ID, array(150,150) );
next_post_link(‘%link’, ”.$nextthumbnail.”, false);
?>
ID, array(150,150) );
previous_post_link(‘%link’, ”.$prevthumbnail.”, false);
?>
”
Remember to remove the ( ” ) at the beginning and end.
Sorry, it didn’t show all of it. Try this:
ID, array(150,150) );
next_post_link(‘%link’, ”.$nextthumbnail.”, false);
?>
ID, array(150,150) );
previous_post_link(‘%link’, ”.$prevthumbnail.”, false);
?>
I tried. Just need to make the changes, then you can delete all my comments….;)