Quick Tip: Next and Previous Posts With Thumbnails

Media rich content is engaging content, right? And giving readers an opportunity to browse through posts linearly is one good way to keep them at your site reading longer, right? So why just give them a title? This quick tip will give you the programming you need to include the post thumbnail and the date of the next and previous posts. Styling is left up to you.


Check for the Previous and Next Posts

These two variables will get the previous and next posts if they exist. Now we can check to see if they exist and use the ID with get_posts() to display any information we want to about each post.


Output the Thumbnails and Other Stuff

This code will go into your single.php template. If the posts exist, we use the ID to get that one post and then create a foreach loop to output the following:

  • A generically labeled "Previous/Next" link
  • The post thumbnail wrapped in a link to the post
  • The title in an h2 and wrapped in a link to the post
  • and the date

Conclusion

Once you have this set up with the styling that you prefer you can do any number of things with the post information. You might have something that looks like this:

Custom Meta Box
Tags:

Comments

Related Articles