I’ve always liked the idea of having related entries shown - it’s a smart system of navigation and helps explore the knowledge available. Hence the first plugin I installed on this Wordpress-based blog was Related Posts by Alexander Malov & Mike Lu.
The aim behind the related posts plugin is to show similar entries already made on your blog, regardless of their category. Think of it as displaying search results before the reader has searched. That’s how useful it can be if it works.
However, the Wordpress plugin did not give very good results when used on this site. Upon investigating the code, I discovered it was only using the post’s URL to compare the current post with other entries. Since my weblog URLs are based on the page title, which on this site doesn’t always highlight keywords from the entry, this was unsurprisingly not proving effective.
The plugin provided the option for you to put hidden keywords in your post which would be used. However I didn’t want to go back and add keywords to my old posts. Not to mention I’d forget the standard keywords between writing posts
Tagging is a job for the computer, not a human…
So I’ve hacked up a modified version, which takes the post content, and calculates word frequency using weightings that can easily be modified (lines 57-62 of the code) for different parts of the post (eg URL, title, content). It then uses these details to match against the MySQL full-text index, (hopefully) returning more relevant results.
The script currently does not use any stemming algorithm or match against category IDs. Those are the most obvious features to add but the latter would require the MySQL query being reworked, and it was bedtime!
If you want to see the MySQL full-text ranking (as shown on this site next to each related posts link at present on this blog) to give you an idea of the certainty of each match being shown, uncomment line 161 in related-posts.php.
The code is not supported and was hacked because I was curious about recommendation algorithms. Improvements or suggestions are welcome. You are free to use and modify this code.
Question: Is there some way to manage file uploads like above from within Wordpress? I’ve uploaded it manually as the ‘upload’ box on the “Write Post” screen said a php file wasn’t a valid image!