Related posts plugin for WordPress

I have been dissatisfied with the existing related entry plugins for WordPress, so, in typical hacker fashion, I wrote my own.The other relatedness plugins I’ve seen work by pattern matching against the title or excerpt of the current article, using something like MySQL’s MATCH AGAINST operator. While this may be acceptable for many people, it didn’t work for me; I figured keywords would be the most effective way of determining entry relatedness. Since I was already adding keyword to my posts, and spending a bit of time thinking about them, determining relatedness using these keywords made a lot of sense to me.

The plugin fetches articles based on keyword overlaps, and displays them as an unordered list. Posts with more keyword matches to the current post are displayed first (i.e., they are more relevant). For example, if the current post has keywords foo, bar, and baz, then a post with keywords foo and bar will be more related than a post with keywords bar. If there are multiple posts with the same keywords, they are displayed with the most recent first. To keep this from degenerating into madness and thrashing the database, only a limited number of related articles (5) are fetched by default. My test dataset had about 100 posts, and many of them have 10+ keywords; before I added the limiting criteria, posts with a lot of keywords were running hundreds of SQL queries. But I was getting excellent results. :)

To apply keywords to your post, create a custom field named keywords, and apply each keyword to it (as a separate value):

Custom Fields Example

Usage is simple:

<?php dlc_related(); ?>

This will emit:

<h2 class="related">Related Posts</h2>
<ul class="related">
  <li class="related">...</li>
</ul>

As you can see, the <h2>, <ul>, and <li> all have a CSS class of “related”, so that they can be styled. Future versions of the plugin will have a function to simply return the related posts, and a version that takes formatting parameters like all the other WordPress tags.

Currently, dlc_related takes two optional parameters: The first is the number of related posts display (defaults to 5) and the second is the name of the custom field to use (defaults to keywords). You can use different values for these:

<?php dlc_related(10, "tags"); ?>

Update:
This plugin has moved to the WordPress plugin repository (thanks Matt!), so you can access it via subversion.

I welcome feedback, patches, feature requests, etc about the plugin.

76 Comments so far

  1. tori on February 16, 2005

    Love the plugin! I would like to suggest or ask for an improvement though…Can you exclude posts that have a date in the future?-tori

  2. Darren on February 17, 2006

    I added this, but I won’t be able to test it until this weekend. You can see the change in Trac, and it’s in the svn trunk and in my code directory. Thanks for the comment!

  3. BillyG on February 26, 2006

    I would love to try this plugin out but seem to have left something out in its implementation. I have added the below code to my single.php and activated the plugin but all I get in return is the header and a black bullet for a potential first item. Can you tell me what I forgot? I assume it is supposed to use a “related” css class but I don’t see that you are using one either…

    <?php dlc_related(5, "tags"); ?>
    <h2 class="related">Related Posts</h2>
    <ul> class="related">
    <li class="related">
    </li> </ul>

    Finally, it didn’t work using “categories” or the default “related” so I tried “tags” but I got nothing with any of them. TIA.

    fyi: my addy is my domain if you care to browse the code yourself

  4. Albert on March 16, 2007

    I’ve done exactly as this guide has said but it does not seem to work for me

  5. Leonardo Pessoa on March 17, 2007

    The same for me =/

  6. nitr021 on March 18, 2007

    Thanks for your plugin, when i get time i will install it.

    I really like the idea of having posts related to each other on the same page. Same as VBulletin’s feature. But wouldn’t it be better to just do like they do and grab the keywords automatically?

  7. Raja on March 21, 2007

    Thanks to your wonderful plug in…
    I dont know how to configure it to show related post for each blog posts…
    Raja

  8. Sebastian on March 21, 2007

    Thanks for the PlugIn!!
    I’ve seen this function on Problogger and have tried to figoure out, how it works - its so usable for the readers! Bevor I got this PlugIn I’ve done this manually and it was sooo much work, especially when I write my posts granular - now I don’t have to remember when I posted smth bout the same topic :)

  9. Rene Grassegger on March 23, 2007

    HI Darren,

    I use this plugin on my personal blog to, It’s so damn simple to get runnin’.

    Love it.

    BIG THX!

    Cheers

    René

  10. [...] Related Posts - This is another must have plugin for getting your blog spidered properly.  This plugin fetches articles based on keyword overlaps, and displays them as an unordered list.  According to it’s homepage, posts with more keyword matches to the current post are displayed first.  This plugin is also useful for gaining higher ranking in the serps because related pages tend to pass higher ranking than unrelated pages.  For example, if you ran a poker site, a link from another poker site would weigh heavier than a link from say, a children’s site. [...]

  11. [...] can increase the page views per reader. In WordPress, you can create a Related Posts section with Darren’s Related Posts plugin. (There are others that work, too.) You type keywords in the Custom Fields section of a post, and [...]

  12. BayTaper on April 10, 2007

    Possible feature enhancement: since there are HOARDS of people using Ultimate Tag Warrior out there already, it would be SICK if you made this plugin automatically work with the hundreds of tags people like me have already implemented across every post of their blogs. I see three key benefits to doing this: (1) You could easily use tags instead of keywords in your algorithm with I’m guessing very little new development work, (2) you’d be able to tap a HUGE installed base for your plugin, meaning a lot more people would take on your plugin, and (3) it makes it a no-brainer for bloggers like me b/c my tagging is already done, I just install your plugin and I’m rolling out related posts in minutes across my entire site. Anyway, just a thought, and thanks for your hard work!

  13. 20 Tips for your Blog on April 11, 2007

    [...] Include a list of related posts beneath each post.เวลาจะเขียนเรื่องอะไร ใส่ Link ที่เกี่ยวข้องที่คุณเคยเขียนลงไปด้วย หรือใส่ Plugin Darren’s Related Posts plugin ช่วยก็ได้ [...]

  14. [...] related posts plugin is a little too manual for me, but at least it does a nice job of adding in related blog entries [...]

  15. Matt Brown on April 13, 2007

    Hi, thanks for the great plugin… This is essentially exactly what I was about to start to write myself, so you’ve saved me a lot of hassle ;p All those automatic-keyword-related-posts plugins are a bit dodgy, in my opinion.

  16. Alan Rimm-Kaufman on April 15, 2007

    Strongly agree with BayTaper [10] — do consider integrating w/ UTW! Cheers –

    Alan

  17. Mohsin on April 23, 2007

    Thanks a lot
    for the awesome plugin.
    I was searching for one which have
    same capability. And i am glad
    i found this page.

    Mohsin

  18. Designer Ella on April 24, 2007

    I had trouble downloading this from your links. Just so you know. I hope this plugin will be perfect for only allowing a few posts circulate through (using it on only a few category single templates [with another plugin]). I’ll let you know how it goes.

  19. Designer Ella on April 24, 2007

    It works perfectly with my edits. I’m using it to highlight related products. :-) The other plugins included non-product posts, but this won’t because I’m not adding keywords.

  20. lance on April 24, 2007

    I uploaded it, activated it and added a keyword custom field of tags. I edited the plugin to reflect tags rather than keywords so that it looks as above. Nothing happens. Help.

  21. Wordpress Plugins on May 2, 2007

    [...] Related Entries I’m currently using this plugin but I’m not very satisfied with the performance of it as it’s not very accurate. I’ll likely change to using Related Posts. [...]

  22. Wordpress Plugins on May 2, 2007

    [...] Related Entries I’m currently using this plugin but I’m not very satisfied with the performance of it as it’s not very accurate. I’ll likely change to using Related Posts. [...]

  23. [...] This plugin adds a list of related posts based on keywords which I think is an excellent feature for your readers to easily navigate to related topics that interest them. Darren’s Related Posts plugin [...]

  24. Kevin on May 20, 2007

    Looks like the file linked on this page gets cut off or is incomplete. I had better luck grabbing the file from the subversion repository.

    http://svn.wp-plugins.org/dlc-related/trunk/dlc-related.php

  25. [...] next step was to further the spiderability of the site.  By using this related posts plugin, I was able to further increase the spiderability of the site by generating tons of inbound links [...]

  26. Classifieds on May 31, 2007

    Cannot get it working.. hmmm

  27. nishanthe on June 13, 2007

    thank you for sharing :)

  28. Welcome2myblog on June 26, 2007

    Thanks. I have tried. Works fine!

    Just need to add one line. That’s all.

    Add this:

    Then in every post, add custom field “keywords”..

  29. [...] Related Posts - This great little plugin allows you to assign keywords to posts, thus creating posts that are related to each other. For example if you write tutorials on your blog and give them the keyword of tutorial you’ll begin to see a list below each tutorial entry called Related Posts. Very handy. [...]

  30. tabs on June 26, 2007

    hi, the plugin works great, no problem with it, but i need help on how to customize/style it, anyone? thanks!

  31. Petr Beňadik on July 4, 2007

    Thank you very much for this great plugin, it works perfectly! I have one question, how can I customize the list with related posts? I need sort this list alphabetical. Thank you for your advice and I am sorry for my English…Petr

  32. Eva Moon on July 5, 2007

    I’m a beginner at this sort of thing and at first it confused me. But I got it running and it works great!

    Thanks so much.

  33. [...] Related Posts - This is another must have plugin for getting your blog spidered properly. This plugin fetches articles based on keyword overlaps, and displays them as an unordered list. According to it’s homepage, posts with more keyword matches to the current post are displayed first. This plugin is also useful for gaining higher ranking in the serps because related pages tend to pass higher ranking than unrelated pages. For example, if you ran a poker site, a link from another poker site would weigh heavier than a link from say, a children’s site. [...]

  34. Denise on July 15, 2007

    Just wanted to say Hi and I love you.

  35. David on July 20, 2007

    I love the plugin, but it does not seem to do very well about matching multiple keywords. I have a post tagged “transportation” “state” “perspective” and “funding” and it pulls up posts with one of those tags, but it fails to pull up a few posts that each have multiple matching tags.

    It seems to pull up the most recent posts that have at least one matching tag and then order them so that the post with the most matches in the list comes first.

  36. Poodlerat on July 25, 2007

    I’d love to see a tag for this that would work inside the loop (like on the main page.)

    Other than that, this works perfectly and I love it!

  37. Yan on July 27, 2007

    Not working for me :(

    ‘keywords’ is set to ‘Ballys’ in multiple posts.

    In one post, I put the following at the bottom, but get nothing back!

    Can anyone help me? ythibodeau@gmail.com

  38. Yan on July 27, 2007

    code did not appear in my previous post.
    it’s

    $lt;? php dlc_related(10, “Ballys”); ?>

  39. Yan on July 27, 2007

    Doesn’t seem to work when I put something else than “keywords”

    :(

  40. Yan on July 27, 2007

    Found my problem :)
    Will email Darren :) It’s something in the puglin…

  41. Yan on July 27, 2007

    Where can I reach you?
    There is a minor bug in your plugin that I fixed and I think lots of user would benefit from this…

  42. Dan on August 2, 2007

    I just installed your plugin (thank you for your work), but I can’t get it to work. It looks fairly simple…and that’s where that ends.

    Would appreciate any feedback on my installation:

    1. I uploaded your plugin to the plugins directory.
    2. I added the code to singlepost.php … there was a place labled for it.
    3. When into several posts and added a group of cross-referencing keywords.

    Nothing happened.

    Thanks,

    Dan

  43. Linda on August 3, 2007

    I get an error message stating that a table in the database doesn’t exist (something related to posts/time, I think).

    Yan, what was the bug?

    I am using the latest and greatest WP.

  44. [...] Posts, Erwin Terong’s Related Posts Link, Christine Davis’ Ultimate Tag Warrior, Darren’s Bowl of Foo’s Related Posts, Peter Bowyer’s Related Posts etc., but none of them to my satisfaction as Aizatto’s [...]

  45. AltaGid on August 7, 2007

    Hello! Help solve the problem.
    Very often try to enter the forum, but says that the password is not correct.
    Regrettably use of remembering. Give like to be?
    Thank you!

  46. eddyra on August 21, 2007

    yo man,
    I tried your plugin and seem working, thanks man. But can I tweak a bit so that it will only pull the really related post?

    I post about wordpress plugin but got sex related post underneath.

    http://eddyra.net

  47. [...] работет и на современном движке вордпресса. Скачать Related posts plugin for WordPress можно тут. Процесс заполнения ключевых слов наглядно показан на [...]

  48. [...] работет и на современном движке вордпресса. Скачать Related posts plugin for WordPress можно тут. Процесс заполнения ключевых слов наглядно показан на [...]

  49. Andrew on September 3, 2007

    Darren, thank you for plugin! I setup it without any problems.

  50. [...] การทำ Related Post หรือรายชื่อลิงก์ไปยังเรื่องที่เกี่ยวข้องกันนี้ ใน WordPress ไม่มีฟังก์ชั่นนี้มาให้ เราจะต้องไปหา Plugin มาช่วยในการทำ Related Post นี้ และฟังก์ชั่นนี้คือ Related posts plugin for WordPress [...]

  51. [...] การทำ Related Post หรือรายชื่อลิงก์ไปยังเรื่องที่เกี่ยวข้องกันนี้ ใน WordPress ไม่มีฟังก์ชั่นนี้มาให้ เราจะต้องไปหา Plugin มาช่วยในการทำ Related Post นี้ และฟังก์ชั่นนี้คือ Related posts plugin for WordPress [...]

  52. dissi on September 8, 2007

    i agree with baytaper:

    quoting: “since there are HOARDS of people using Ultimate Tag Warrior out there already, it would be SICK if you made this plugin automatically work with the hundreds of tags people like me have already implemented across every post of their blogs”

  53. dissi on September 8, 2007

    … but maybe UTW does that… i have to take a look…

  54. dissi on September 8, 2007
  55. gtd on October 3, 2007

    Hi Darren,

    I love what your plugin does, but on some pages (not on all) I got an error like:

    “[The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay]
    SELECT x.post_title AS title, p.post_id FROM wp_posts…”

    and so on. Please look at http://www.strategievincenti.net/2007/10/the-secret-il-segreto/ for an example.

    Please tell me how I can fix this problem.
    Thanks in advance

    ciao
    alexander

  56. Petr Benadik on October 30, 2007

    Hi Darren,
    thank you very much for your great plugin. We use it on our botany websites, but since last week we have had a problem. If we today write a post with same keyword which we had added before last week, the todays post isn´t displayed in old posts - concretely http://botany.cz/cs/carex-elongata/

    Please help us with solving this problem, because we create a very big botany database and this is a very big problem for us.

    Thank you very much for your advice!

  57. [...] Darren’s Related PostsDas letzte Update dieses Plug-ins liegt weit zurück, und es scheint nur wenig Resonanz gefunden zu haben. Der Ansatz basiert auf Keywords (Methode Nr. 2).    [...]

  58. LusciousGirl on November 5, 2007
  59. Michael Weir on November 6, 2007

    Cheers Darren. Been looking for a plugin just like this.

  60. wirawiri.com on November 22, 2007

    thanks for the plugin, darren. still trying learn about it :)

  61. exinco on November 23, 2007

    nice explanation, so far not install yet to my new blog. i’m on my way to post content before install any tools

  62. Shelby on December 12, 2007

    I installed this plugin and like many people here, nothing happens. It’s activated the code is placed in single.php but nothing shows up. Whee can I get support?

  63. Shelby on December 12, 2007

    I guess this mod doesn’t work with the tags of the latest version of wordpress. As explained here, you have to manually add the keywords in the custom fields of each post. Forget that!

  64. Idetrorce on December 15, 2007

    very interesting, but I don’t agree with you
    Idetrorce

  65. fatfighter on January 2, 2008

    I activated this plug-in but I don’t understand how to use it. Can you help please?

  66. modjo on February 9, 2008

    Great plugin! Increases blog reading :) cool. Thanks.

  67. [...] Darren’s Bowl of Foo - Related Posts Plugin For WordPress [...]

  68. [...] Darren’s Related Posts plugin – As your blog grows you will certainly like to have this plugin which will help you to detain your readers on the blog, by showing related posts at the end of your post. [...]

  69. Marisha on April 12, 2008

    I can’t set it up :(

  70. aliweb on May 1, 2008

    It doesn’t work for me. I activated it and placed the code in single.php but it doesn’t display anything.
    Am I doing something wrong?

  71. [...] Darren’s Bowl of Foo - Related Posts Plugin For WordPress [...]

  72. on May 26, 2008

    . .

  73. [...] Darren’s related posts показва публикации свързани с текущия по ключови думи. [...]

  74. Herbert Malzahn on September 17, 2008

    Hello, where is the Download-Link? I can´t find any correct Link.

  75. [...] Darren’s Bowl of Foo - Related Posts Plugin For WordPress [...]

Leave a reply