Next and Previous Posts With Thumbnails Preview

Next and Previous Posts With Thumbnails Preview

Today we will learn how to make wordpress post page Next and Previous Posts With Thumbnails Preview.

Recently One of my client want to create Previous and Next post card. i can be done by following code

Default Previous and Next nav code is

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.

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

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:

Md. Elias
elias1435@gmail.com
No Comments

Post A Comment