I’ve added a new “related posts” feature to individual posts on this blog. It uses a combination of tags, categories and featured posts to display three other posts with content that’s likely to be relevant.
Rather than download and install a third-party plugin, I decided to try coding it myself to keep my coding skills in working order. The code I added to the template does this:
- First it tries to find the three most recent posts with one or more tags that match those of the post. It will skip anything that doesn’t have a post thumbnail
- If it failed to find three posts matching by tag, it looks at the post’s category instead to fill the remaining slots.
- If all else fails, it goes for the featured posts, regardless of what they’re about. This is the fallback position, and it should always be able to find three such posts.
There’s still a bit of CSS formatting to be done, but it’s more or less there now.
Let me know what you think.