Next & Previous Post Titles With Thumbnails
-
I am building a custom theme and taking advantage of a relatively new feature in WordPress, post thumbnails (https://codex.www.ads-software.com/Post_Thumbnails). Since the documentation is still pending, I figured that others may find this useful too. Keep in mind that this is to be placed in the single.php file.
Here is the code to grab the next post title & the thumbnail:
<?php next_post_link('« %link','%title', TRUE); ?><br /><?php $nextPost = get_next_post(true); $nextthumbnail = get_the_post_thumbnail($nextPost->ID, array(150,150) ); echo $nextthumbnail; ?>
And this is the code to grab the previous post title & the thumbnail:
<?php prev_post_link('%link »','%title', TRUE); ?><br /><?php $prevPost = get_prev_post(true); $prevthumbnail = get_the_post_thumbnail($prevPost->ID, array(150,150) ); echo $prevthumbnail; ?>
I hope that this is useful, and remember that your theme must have post thumbnails activated in order to work.
- The topic ‘Next & Previous Post Titles With Thumbnails’ is closed to new replies.