Similarity

I have been using Darren’s Related Posts plugin (DRPP) for a long time. For my purposes it was the best plugin for showing related posts that I had encountered. After a while I decided that I was not completely satisfied with the way that it seemed to favor more recent posts. I developed a new algorithm that I felt would not give preference to newer posts unless they were actually more related.

When I learned that WordPress would be adding native tag support in version 2.3 I decided that I would create my plugin to work with tags after they arrived. Life got busy so I never worked on the plugin until version 2.5 came out (partly because I wanted to convert the post_meta “keywords” from DRPP to tags). I finally buckled down and created my Similarity plugin this week. I have tested it on version 2.3.3 and version 2.5 (I assume it will work with any version of 2.3). I will continue to test it on new versions of WordPress as they are made public. (Przeczytaj opis wtyczki po polsku)

Latest Version 2.13.1 (September 9, 2009)

New options make it possible to layout and style the php function generated lists (for sidebars) independent of the auto-generated list. – Version 2.13 was released with an incomplete development copy of the plugin so it did not have the promised functionality. (In other words, “Pay attention Miller.”)

To install it simply unzip the file linked above and save it in your plugins directory under wp-content. In the plugin manager activate the plugin. Settings for the plugin may be altered under the Similarity page of the Options menu (version 2.3) or Settings menu (version 2.5 or later).

Options include:

  • Number of posts to show – this is a maximum, it won’t invent connections that don’t exist, set it to 0 (or less) and it will display all matches.
  • Minimum match strength – enter a number between zero and one (one being a perfect match) and items related weaker than the number indicated will not be included – this limit is ignored for the one extra if that option is used.
  • Default Display if no matches – if there are no matches this is what will be displayed, this is not displayed if there are matches, but fewer than the set maximum.
  • Text and Codes before the list – assuming you want to do a list this is where you would place the <ul> or <ol> You may also place any other code you would like to have preceeding the list. (There are two boxes here – one for function calls in your template and one for auto-generated lists.)
  • Text and Codes after the list – this would be the place for </ul> or </ol> You may also place any other code you would like to have following the list.(There are two boxes here – one for function calls in your template and one for auto-generated lists.)
  • Output template – this would be where you place the <li> tags. (There are two boxes here – one for function calls in your template and one for auto-generated lists.) There are also 4 template tags you may use (in any configuration you can imagine) to define how the results are displayed
    • {link} – provides a link – equivelent to <a href=”{url}”>{title}</a>
    • {strength} – outputs the calculated degree of relatedness
    • {url} is the permalink for the related post
    • {title} is the title for the related post
  • Display format for similarity strength – Value displays the {strength} in a decimal format (0.873), Percent displays the {strength} in a percentage format (87.3%), Text displays {strength} as a word (Strong, Mild, Weak, and Tenuous are the defaults), and Visual displays a color block (Green for 100% fading to Yellow and then to Red for weak connections)
  • Relative mixing weights – these values determine the ratio given to the weight of tags vs categories when using the sim_by_mix function. Invalid ratios are treated as a 1 to 1 balance.
  • Custom text for strength – allows you to insert custom text (including markup) for the strength indicator when using the text display format. (Hint: using markup allows for the possibility of showing custom images.)
  • Show one more random related post – dig deeper into the related post list with one random selection (you can set a minimum strength for these random items).
  • Auto-display a Similarity list at the end of a single post – without modifying any templates.

The plugin allows for three function calls anywhere in your page templates or their shortcodes in text widgets (all use the same options):

  • <?php sim_by_tag(); ?> – determines similarity based on the tags applied to the posts (shortcode: SIM-BY-TAG)
  • <?php sim_by_cat(); ?> – determines similarity based on the categories assigned to the posts (shortcode: SIM-BY-CAT)
  • <?php sim_by_mix(); ?> – determines similarity based on the tags and the categories with the relative weights determined by the relative mixing weights setting (shortcode: SIM-BY-MIX)

Alternately you may choose to auto-display any of the similarity lists at the end of posts on single-post pages without getting into the php by selecting the function you wish to auto-display on the Similarity options page.

This entry was posted in meta, pictures, technology and tagged , , , . Bookmark the permalink.

183 Responses to Similarity

  1. Pingback: WordPress Plugin Releases for 01/23 | Weblog Tools Collection

  2. Pingback: WordPress Plugin Releases for 01/23 | Wordpress Blog NL

  3. Pingback: WordPress Plugin Releases for 01/23 | BlogBroker24-7

  4. Pingback: WordPress Plugin Releases for 01/23 | FOX-CUB.COM

  5. Li-An says:

    I was using the Simple Tag Plugin for this purpose (based on tags) and I have some questions: is there a way to “mix” tags and categories similarity in a single list ? If you get a blog with a lot of posts, will be some problem of time to calculate the list ?
    Thank you for eventual answers…

    • David says:

      There is no way within this plugin currently to mix tags and categories. That was something I had considered doing in a future version. Knowing that there is some interest I will work on that – it’s a bit complex. On the question of performance, I really don’t know. I have never had nor heard reports of performance issues, but I have no data outside my own blogs. I have nearly 1000 posts now and have never had any issues with slowing. The performance probably also depends on how many tags are being considered – I have nearly 400.

      Since you bring up Simple Tags I would like to share one important way that my algorithm is different than every other related posts plugin I have found (including Simple Tags) – mine gives more weight to less common tags (or categories) when calculating similarity. In other words, if two posts share a very rare tag they can get a higher similarity score from that than they do from sharing two very common tags (it depends on how rare or how common the various tags are). Most plugins calculate based simply on the number of tags in common (of course the number of shared tags is a factor in mine too).

      • David says:

        Thanks to the question by Li-An I finally tackled the function to mix categories and tags in calculating similarity. Thus the release of version 1.3 today.

  6. Pingback: WordPress Plugin Releases for 01/23 | BlogBroker24-7

  7. Pingback: WordPress Plugin Releases for 01/23 | Web2.0

  8. Pingback: Wizreport » WordPress Plugin Releases for 01/23

  9. Pingback: Wizreport » WordPress Plugin Releases for 01/23

  10. Pingback: Wizreport » WordPress Plugin Releases for 01/23

  11. Li-An says:

    Thank you for your quick answer … and what an answer ! :-) I was bored to create “artificial” tags in Simple Tags to create a list of related posts. I install your plugin right now !

  12. Li-An says:

    It works great ! I wanted to create a french translation for the plugin but it does not manage .po and .mo files as I can see ?

  13. Li-An says:

    I tried to modify the weight of the tags to make them more important but the result (showing 5 links) is that it shows the same links two or three times for some posts !?!

    • David says:

      That’s a problem. Early on in development I ran into a problem of having a post show up twice in the list but that appeared to be fixed before I released version 1.0. I’ll look into that.

      • David says:

        This new problem was related to post revisions (which did not exist when I first created Similarity). It is fixed in version 1.4 as of 1/27/2009.

  14. baron says:

    hi. Thanks for plugin

    perfect.

    Regards

  15. Li-An says:

    I have a suggestion for the showing of the strength. As I was a mathematic teacher, I know how hard it is to convert numbers into something clear to understand. I don’t know if it’s easy to to but maybe it could be interesting to show a colored image instead of a number (even a percentage :-) ). Something like “green” for 100% to 70%, orange for 70% to 30%, red for 30% to 0%. It’s just an idea :-)

  16. Li-An says:

    Great work !
    A have some new philosophical question about the plugin: for the moment it shows the “best” posts for a category and chosen tags. But I’m afraid it’s always the same “good” posts that are shown and so, some posts will never be shown. I choose the random display with Simple Tags but your plugin is interesting because it shows the “best related” posts. Well, it was only some thinkings :-)
    Thank you again for your efforts.

  17. David says:

    The plugin actually randomizes among posts that are equally related. I wonder if it would make sense to randomize without considering degree of relatedness – I’d have to think about that.

    • Li-An says:

      Yes, I understand your point of view. For the moment I show 4 links. Maybe it could be nice to show the 3 “best” links and a “more random” 4th (not completely random, of course). I must admit I have no good solution (I thought I may use your plugin AND Simple Tags in the same time): if you show the “best” links it’s nice for new visitors but “old” visitors will already know the posts and it could be nice to make them discover something “uncommon”. It’s only ideas I got, maybe it has no sense.

      • David says:

        There are other plugins that will display random posts from your archives but if you want one that is random but related I have an idea that could accomplish that. I’ll call it the “Plus One” option – when I implement it.

  18. Hello,

    Similarity ist the only Plugin that brings good results. The only problem is that it shows post that are not public or that are drafts. I have many of such and therefore I cannot use this plugin. How can I fix that? Or, will you fix this in the next update?

    Thanks,

    Der Kritisator

    • David says:

      What version are you using? Versions 1.7 and 1.8 should hide private posts if you are not logged in. For users who are logged in private posts will show for the post author (meaning the author of the private post) or for users who have the ‘read private posts’ capability (usually admins). As of version 1.8 posts that are scheduled for future publication will not be shown.

      If you are using the latest version and not logged in and are still seeing those posts please let me know so that I can look into that problem.

      • OK, that’ a solution. I use v1.8 and I’ll test this. Thank you for the help.

        DK

        • Hmm, just test it. It doesn’t work anymore. When I am logged out, I can still see these posts. I use WP 2.7.1. A good example are two pages that don’t have any tags. I this case, Similarity “matches” the non-tags posts/pages (drafts) and dislpays it on the sidebar.

          What can I do?

          Thanks for help,

          DK

          • David says:

            If you are using the sim_by_cat or sim_by_mix calls there will be matches even without tags. I will look into this, but can you let me know if you are seeing private posts in your list, or are you just seeing drafts?

  19. Ok, I’ve used . I’ll look for an other expression.

    > but can you let me know if you are seeing private posts in your list, or are you just seeing drafts?
    Pages across Posts. I just seeing drafts. But for me, drafts are not yet for public.

  20. Jokes says:

    Great plugin, I just installed it at http://www.viewjokes.com/ and it worked like a charm.

  21. lazar says:

    your plugin does not figure out proper permalink redirects, but points to default …?id=123 type of url.

    :(

  22. Li-An says:

    Hello,
    thank you for the last version and the new option. But it seems the minimum strength works only for the “regular” posts not the random one ? (I send you the french translation)

    • David says:

      I tried to state that the random post ignores the minimum strength parameter but perhaps I did not say that clearly. Thanks for the updated French translation.

      • Li-An says:

        Maybe it will be cool to have the option to choose a random post with a good strengthness. When there is a lot of related post with a good strength it’s a pity the random post is a one with a poor strengthness…

  23. Richard says:

    I have 80,000+ articles on my blog and added at least 30-40 new articles each day, I like this plugin and when installed on my blog my server going crash (over load process), already installed super wp cache but look like problem still persist.For temporary I deactivated this plugin, any tips for me guys?Thanks.

    • David says:

      I can imagine that 80,000 articles would start to cause a performance issue, especially if you have many tags and categories and especially if you use the sim_by_mix function. If you are using sim_by_mix you might try using sim_by_cat or sim_by_tag. Also, I would suggest that you not use it on pages with multiple articles (archives, main page, or search results come to mind). Unfortunately I don’t really have any other suggestions since I have no sites with a database anywhere near that large.

  24. Li-An says:

    Hello, David,
    did you receive my mail with the translation and the problem I met ?

    To Richard: I read that this kind of plugin need a lot of server processing and it’s not surprising you met problems. Maybe you can try some others (like Simple Tags) to see if it works better.

    • David says:

      I have received the translation. The fix for the bug in the minimum strength for a random post is available from the Similarity link on this page (along with your updated translation files), but due to problems with the repository I have not yet been able to get the fix into the WordPress plugins directory.

  25. baron says:

    Works great, thank you

  26. krzychu says:

    Great plugin!
    I use it on my personal website – wholly in Polish language – and works pretty good. Thank you!

    But there is one small issue: when I turn on option to show random posts I see word ‘RANDOM’ as mark. How can I translate ‘RANDOM’ into Polish ‘losowe’? It seems that I have to make some hardcoding in similarity.php file.
    IMVHO it would be great to have new option in settings of the plugin to put custom (here: Polish) word instead ‘RANDOM’.

    • David says:

      There is a plugin called Codestyling Localization. If you install that on your blog it adds an item on the tools menu where you can create a localization file in Polish for Similarity (and many other plugins). If you do create a polish translation let me know and I will include it with Similarity. One of my users has used Codestyling Localization to create the French translation files that come with Similarity.

  27. Richard says:

    @David

    Thanks for your reply.I put this function on page only.I already try with all functions but that’s not resolving the problem.Yes you are right there each article had 8-10 tags.
    Maybe a lot hit on page caused high query on database.I got 20,000-22,000 visitors daily.

    @Li-An
    Thanks for your suggestion, unfortunately I don’t like Simple Tags plugin. :D

    Just to bad I can’t use great plugin like similarity, but I will be monitoring this plugin dev progress, maybe someday David found his magic to make this plugin working with “big boy” wordpress. :D

    Again good work and thanks for all reply.

    • Li-An says:

      There are some other plugins offering the same kind of related posts. Maybe you can test them :-)

    • David says:

      Thanks for the vote of confidence Richard. With that many posts and that many tags per post I’m not surprised that you would have performance issues. I’ll have to think about how I could make this work under those conditions.

  28. Taman Royal says:

    Hi,

    I am using WP 2.7.1, and plan to install you plugin and display it in widget area, should I just select text widget and paste into widget content?

    Also, is it possible to disable the display of similarity in post area? Because it already display in widget.

    TIA

    • David says:

      Similarity does not automatically display in your post so there’s nothing to disable. If you want to use it in the widget area you can either place it before or after the widgets (you have to know your php) or else you can make sure you have at least version 2.3 of Similarity and use a shortcode (you can’t add php function calls to widgets as far as I know). The only catch with that is that I don’t know how it will function if you display it on a page that shows multiple posts and I don’t know if you can have a widget that only displays on single post pages.

      The option to automatically display Similarity results and the ability to have shortcodes that only display on single post pages are coming in the next version.

      • Taman Royal says:

        Hi David,

        Thanks for your prompt reply. For displaying in single post page, I must modify single.php in my theme and at the end, call another alternative sidebar.php which have your php insert code.

        Looking forward to your new features in next release.

        Meanwhile, I have implemented some alternative related posts plugins in my site, I hope it functions correctly.

        BTW, what kind of plugins you use for your comments. It can show it in thread discussion. Very nice…

        • David says:

          The new release is out with shortcodes that only show on single post pages. That should suit your needs.

          As for my comments I use two plugins – “Subscribe to Comments” and “WP Ajax Edit Comments” but neither of them affects the threaded discussion – that’s a new feature in WP 2.7. If you have WP 2.7 or higher. You just need to make sure that your comment form makes a call to comment_id_fields(); instead of some older code. Let me know if you need help in trying to implement that.

  29. Angie says:

    Hello David,
    Your Similarity plugin works great – thank you very much!
    I have a question though: when I installed your plugin it worked fine in my (multiple) post page, but now it only works on single post pages. Any idea why?

    • David says:

      I placed a restriction on shortcodes in version 2.5 so that they would only work on single post pages because I had learned that they caused performance issues on some multi-post pages. I have just released a new version (2.6) with three new shortcodes that will work on multi post pages the shortcodes are SIM-BY-TAG-MULTI, SIM-BY-CAT-MULTI, and SIM-BY-MIX-MULTI. If they were working for you just change to the multi version of your shortcode.

  30. Angie says:

    Dear David,
    You are certainly amazing. Such a swift reply, and such a professional response to my question!
    Thank you very much!
    Angie

  31. Angie says:

    Unfortunately…
    It still doesn’t work on my multi post pages :(
    I’m using your shortcode [SIM-BY-MIX-MULTI]
    The former version (2.4?) gave no performance problems on my site.
    Do you have any suggestions I might try?
    Should I go back to 2.4? – If so where can I find that?
    Tnx in advance,
    Angie

    • David says:

      The version that was working for you is version 2.3 (I skipped version 2.4) – you can download that version here. My first suggestion would be to try that version again and prove that it is still working. My other suggestion would be to tell me where in your code you are using the shortcode so that I might be able to identify a reason it would not be working.

  32. Angie says:

    The 2.3 version works fine for me.
    I use the shortcode at the end of the posts, but have tried various positions with the 2.6 version…
    Is there a way to make the similar post links appear at the end of the post instead of the beginning?
    Thank you for all your trouble, I really appreciate it.
    Angie

    • David says:

      I’m glad that 2.3 is working for you. I’ll have to dig into my code and see if there are any differences between 2.3 and 2.5 that I had forgotten about.

  33. Angie says:

    Do you know of a way to make the similar post links appear at the end of the post instead of at the beginning?

    • David says:

      Because of the way WordPress processes shortcodes they always appear at the beginning of the post or the widget where they are located. To have your list appear at the end of your post you have two options – you can use the auto-display option or else you can modify your templates with the php function call. The auto-display option only works on single post pages right now and is not available prior to version 2.5 but if you wish to use the php calls and need help I would be more than happy to assist. It’s pretty simple.

      • Markus says:

        David, tried using the auto-display option but it doesn’t show any output at all. Works with other options and shows the posts at the beginning of single posts but I want it to show either in the end or in the middle of the posts.
        am using the latest wp version.
        Is it something I am missing?

        • David says:

          Which auto-display option are you using (so that I can take a closer look)? Also, I looked at your site and I can’t tell if you are using any tags (they aren’t displayed where I can see them so I can’t tell).

  34. Angie says:

    You are right David, I should make the php calls in the coding of my site’s templates. I did, and it works fine now with 2.6 – Thanks again!

  35. Anton says:

    Hi David,

    Thanks for the great plugin.
    Unfortunately, it displays related links at the top of my posts and I want them at the bottom.
    Is that possible and how?

    Thank you

    • David says:

      To have full control over the display you can use the php calls by altering your template. I am working on a way to have the automatic display functions display at the bottom of the post more consistently.

  36. Anton says:

    Unfortunately I don’t know good php well enough to change the code. If you manage to put links at the bottom, please let me know when the updated version is ready.
    Thank you

    • David says:

      Yes, there’s little use making an auto-display function specifically so that people won’t have to alter their php if it doesn’t function the way that people expect. I finally found what was causing the trouble and have uploaded the new version. As of Similarity version 2.7 the list of similar posts shows at the bottom of the post.

  37. Anton says:

    Downloaded and installed.
    Fantastic, it works!

    Thanks a lot, David :)

  38. Gerhard says:

    David, is it possible, to make the auto-display function optionally working for “pages” too?
    In the meantime, I’ve solved it with php-code in the footer of the pages.

    • David says:

      That should be doable. I’ll see about getting that into the next version. Because pages cannot have tags assigned to them the only function I would make available would be the sim_by_cat function.

      • Gerhard says:

        the auto-display function for “pages (with tags)” is working very fine and it is very clear in the options to activate it. Many thanks for your great work. The Lord Jesus bless you much!

  39. Li-An says:

    Simple Tags gives the ability to stick tags on pages.

  40. Hi, I am using your plugin

    I have tried to set it so that nothing shows up if there are no related posts. No matter what I enter into #Default display if no matches:# it seems to show ‘related Posts’ always

    Can you advise?

    Nick

    • David says:

      What’s happening is that the #Text and codes before the list# always shows – like a list header. I can tell you how to fix it so that is not the case, but it brings up a question I have had in designing the plugin – Should #Default display if no matches:# stand in place of items in the list, or should it stand in place of the entire list? You can see that I chose the first option, but the more I think about it I think it would be easier to support the second option. What do you think?

  41. I think the second option would make the plugin perfect!

  42. Thanks a million for your prompt response and helpful email. If only all people were like that.

  43. Pingback: Wordpress : Mes bonnes pratiques | Un a un, le blog du marketing interactif

  44. Hello Dave,

    I have problems with the new function with the shortcode changes since version 2.5. Downloading v 2.3 gets no solution.

    The problem: On my hompage (multiple articles) the top post should be the one for creating the similar articles in the sidebar. In the past, this works just fine, but for now, only the single post will display the correct similars. In the home view the output is like random.

    I don’t use the dashboard. In the sidebar.php I’ve used the shortcode.

    What can I do?

    Thanks, JN

    • David says:

      I’m not exactly sure what behavior to expect when you want to display a similarity list from a single post on a page that outputs multiple posts. That might explain why it appears to be random for your homepage. I’ll think about it and see if I have any ideas.

  45. Olivier says:

    Hello David,

    I have tried to include shortcode in the sidebar text widget but sounds like it doesn’t work in 2.8 :(

    • David says:

      I’ll have a look and see what I need to do to have it start working in 2.8

    • David says:

      Could you be more specific about which shortcode you are using? (I looked at your site and the similarity list seems to be showing up just fine below the posts on single post pages although I can’t tell if that is from a shortcode or some other method.)

      • Olivier says:

        On my site, I have used the php function call in my theme. I have tried few shortcodes in a sidebar text widget but none worked so I have removed these.

        • David says:

          Thanks for the letting me know. I tried shortcodes in my sidebar (running on 2.8) and everything seems to work as expected. If you want to try shortcodes again you should be careful that you are using ALL CAPS in the shortcode and that you are using hyphens (ALL-CAPS) rather than underscores (ALL_CAPS) like you use in the PHP calls. Aside from those hints I can’t reproduce your issue – sorry.

      • Hallo David,

        thanks for supporting. I use this shortcode:

        This just works perfect on the single posts. In the past, I saw no difference between a single post and the top most of the home. But may be that I’m wrong. However it would be great if this could be an option.

        • David says:

          The shortcode got removed in the comment – try not adding the brackets around it.

          • Olivier says:

            Well, I tried again following your rules with ALL CAPS. Doesn’t change :(

            I have tried to debug a bit. If I put the shortcode in a post content, it works fine. But in a text widget, it doesn’t :(

          • David says:

            Silly me – I forgot that there’s a trick to shortcodes working in sidebars. Some themes are not set up to accept them. If you are comfortable with editing your theme there is a simple fix detailed at WP Recipes. You have to add add_filter(‘widget_text’, ‘do_shortcode’); in the functions.php file for your theme. (I added it as the last line of code in my functions.php file.)

          • Olivier says:

            You are a king! Fixed the issue!
            Now, I have another problem, the SIM-BY-MIX-MULTI doesn’t seem to work on multiple posts pages. One nice thing would be that on single post pages, it automatically use the single SIM version and on multiple page, the MULTI SIM version. On sidebar, you cannot add php code so you can’t filter to say on multiple post use this one and on single, that one…
            Thanks!

          • David says:

            Try the SIM-BY-MIX shortcode and see if that does what you want.

          • Olivier says:

            Yes it does. There is just a small bug but it may not be related to your plugin, I don’t know… The text of the similar posts is going into the previous widget within the sidebar instead of the one it is supposed to be into, really strange…

        • David says:

          If you update to version 2.9 of Similarity there are new php functions for use in sidebars that show on multiple pages. These functions produce a Similarity list based on the top post of the multi-post page (rather than the bottom as was being displayed before).

          Enjoy.

  46. Peter Lurie says:

    Thanks for the plugin.

    A question: my front page is a “page”. I have the 2 most recent posts in my base (Aktuell) category always displaying there. I’d like a list generated with Similarity, below the 2 post extracts, but EXCLUDING the 2 posts already displayed.

    I have implemented it on the website above. Perhaps you could check it out.

    Is there any way I can do this? (I am still using 2.7.1)
    Thanks
    Peter

    • David says:

      The way you are currently using it will display a similarity list based on one of those two posts and it will exclude the post that is used to generate the list. The plugin does not have an option to exclude other posts on the page.

  47. Sudeshna says:

    Hi david,

    I have a little problem installing the plugin. I have activated it in my wordpress blog but its not showing in the posts. I have a hosted service and wordpress2.8 installed on my home folder

    • David says:

      Could you tell me a little bit more about the settings you have for the plugin? For example, have you added the php calls to your template, or added shortcodes anywhere to display the list? Are you relying on the automatic list, and if so what settings do you have on the “Auto-display list from function”, “Number of posts to show”, and “Minimum match strength” fields of the Similarity Options page?

  48. Bjoern says:

    Hi David, I just translated Similarity to German. How can I give it to you for integration?
    Nice Weekend
    Bjoern

  49. Pingback: Wordpress-Plugins: Similarity | turbobrain

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>