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.

103 comments so far

  1. tori on

    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

    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

    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

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

  5. Leonardo Pessoa on

    The same for me =/

  6. nitr021 on

    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

    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

    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

    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

    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

    […] 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

    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

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

    Alan

  17. Mohsin on

    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

    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

    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

    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

    […] 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

    […] 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

    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

    Cannot get it working.. hmmm

  27. nishanthe on

    thank you for sharing :)

  28. Welcome2myblog on

    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

    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

    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

    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

    Just wanted to say Hi and I love you.

  35. David on

    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

    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

    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

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

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

  39. Yan on

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

    :(

  40. Yan on

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

  41. Yan on

    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

    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

    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

    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

    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

    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

    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

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

  54. gtd on

    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

  55. Petr Benadik on

    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!

  56. […] 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).    […]

  57. LusciousGirl on
  58. Michael Weir on

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

  59. wirawiri.com on

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

  60. exinco on

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

  61. Shelby on

    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?

  62. Shelby on

    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!

  63. Idetrorce on

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

  64. fatfighter on

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

  65. modjo on

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

  66. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  67. […] 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. […]

  68. Marisha on

    I can’t set it up :(

  69. aliweb on

    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?

  70. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

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

  72. Herbert Malzahn on

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

  73. MLMовка on

    Oh… how it’s hard to setup whith all of this keywords :( I can’t got it.

  74. Азбука Здоровья on

    That’s what I really needed!
    Thanx a lot.

  75. Answering Service on

    great thanks for sharing..

  76. webdesign on

    Wow nice addition will try it out as soon as possible:)

  77. Gavrilin on

    Да,aleks,побороть лень, действительно иногда очень сложно..

  78. Chris on

    This looks like a great plugin–I’m going to implement it on my new site.

  79. seo link directory on

    It was a nice plugin. i have tried. good work….

  80. tyrone on

    great plugin thank you !!! One featrue request though which I think would be really useful. Is there any chance we could have the category of the post listed as well, e.g.:

    related posts:

    > post 1 in category 1
    > post 2 in category 1

    etc

  81. chocolate on

    nice plugin..been looking for this.thx

  82. Michey on

    Darren, you make my day. I have noticed “related topics” in my favorite blogs but I didn’t know how to get it.
    Now I know and I have to thank you for this.
    Thanks
    Michey

  83. Eva Moon on

    I’ve been using your plugin for ages and have really liked it, but I just upgraded to WP 3.0 yesterday and all the related posts have disappeared! I’d really prefer to get this working again rather than look for a new plugin. I’ve got over three years of posts that would have to be updated otherwise.

  84. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  85. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  86. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  87. […] my new WordPress template I added Post Related Plugin, WP-Stats, WP-UserOnline and WP-PostRatings for Poems and Inspirational Pages. Posted on August […]

  88. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  89. […] يجب ان يكون هدفك الاساسى ان تجعل زائر الموقع “يتورط ” فى مزيد من التصفح لمحتوي المدونة، ولا تستغرب من كلمة يتورط فهى ابلغ تعبير، يجب ان تحفز القارئ على تصفح المدونة بالكامل، ايضا بعد زوار الموقع قد يصلون للمدونة عن طريق محرك البحث فيوصلهم لمقال بعينها … عندما تعرض لهم مقالات تحتوى على معلومات مشابهه للمقال المقروء ستزيد من كثافة التصفح لمقالاتك، الوردبريس يوفر عدة اضافات ل ” مقالات ذات الصلة ” مثل Related Entries plugin ، لو اردت المزيد من التحكم بكتابة كلمة دلالية ليأتى بالمقالات التى تحتويها اليك اضافة Darren’s Related Posts plugin […]

  90. Vietpan.Net on

    thank

  91. […] matching keywords with the Related Entries plugin. If you want more control (with more effort), use Darren’s Related Posts plugin. You type keywords in the Custom Fields section of a post, and posts that match the keywords are […]

  92. Delphic on

    It’s a relief that I was able to come across wordpress.com: it has the knowledge I was really searching for. You’ve produced a very good resource and it’s clear you possess a thorough comprehension of the topic. You have opened up my mind to numerous insights related to this particular topic using intriguing and effective content.

  93. […] Darren’s Bowl of Foo – Related Posts Plugin For WordPress […]

  94. […] يجب ان يكون هدفك الاساسى ان تجعل زائر الموقع “يتورط ” فى مزيد من التصفح لمحتوي المدونة، ولا تستغرب من كلمة يتورط فهى ابلغ تعبير، يجب ان تحفز القارئ على تصفح المدونة بالكامل، ايضا بعد زوار الموقع قد يصلون للمدونة عن طريق محرك البحث فيوصلهم لمقال بعينها … عندما تعرض لهم مقالات تحتوى على معلومات مشابهه للمقال المقروء ستزيد من كثافة التصفح لمقالاتك، الوردبريس يوفر عدة اضافات ل ” مقالات ذات الصلة ” مثل Related Entries plugin ، لو اردت المزيد من التحكم بكتابة كلمة دلالية ليأتى بالمقالات التى تحتويها اليك اضافة Darren’s Related Posts plugin […]

  95. rowenaalenav.soup.io on

    Now I am ready to do my breakfast, afterward having my breakfast coming over again to read further news.

  96. Awesome! Its in fact amazing paragraph, I have got much clear idea on the topic of from this article.

  97. Johna752 on

    Normally I do not read post on blogs, but I wish to say that this writeup very compelled me to try and do it! Your writing style has been surprised me. Thanks, quite great article. eedceedcdddk

  98. Jeff on

    This is an older blog but its still a great read in 2014. Thank You!

  99. inspirational film on

    Ridiculous quest there. What occurred after? Good luck!|

  100. […] number three is called Darren’s Related Posts plugin, and it helps you organise the content very well inside your blog. This is part of branding your […]


Leave a reply to BillyG Cancel reply