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.

About David

David is the father of 8 extremely organized children (4 girls / 4 boys) who is constantly seeking answers to tough questions related to parenting, education and politics while moonlighting for 40 hours each week as a technology professional. He also enjoys cooking, gardening, and sports.
This entry was posted in meta, pictures, technology and tagged , , , . Bookmark the permalink.


182 Responses to Similarity

  1. Rajiv says:

    Nice plugin! This does exactly what I wanted….

    My only concern: This plugin should have had separate styling available for sidebar one and the post one…

  2. Nethelper says:

    thanks for this nice addon 🙂
    i just want to say thanks 🙂

  3. Why there is nothing displayed on my WP?
    I already install the plug-in on

    • David says:

      My first guess would be that you need to go to the Similarity Options page and set the “Auto-display list from function:” setting to something besides “none.”

      If you want more flexibility you can choose add a php function call anywhere in your template (assuming you are comfortable altering your theme templates), but the simplest way to get a list is to set that option and have lists automatically displayed at the end of your post on the single-post pages.

  4. Kelly says:

    This is a great plugin, but I was wondering if it is possible to display the list of related posts alphabetically by title instead of by date published?

    • David says:

      The list is not based on publication date – it is based the degree of relatedness – the posts at the top are the most closely related to the main post – equally related posts are in random order.

      I suppose that it could be made to display the posts in alphabetical order but it is not currently designed to do that.

  5. Tony says:

    I have to say that this was a lucky day for me. I’ve been trying to get a related plugin that works for me for sometime.

    Thanks a lot. Wondering though how to remove those 1.0 and 0.00 at the end of the links.

    • David says:

      You have two options to remove those – you can edit your output template so that there is no reference to {strength} or else you can choose another option in the Display format for similarity strength. You apparently have it set to “Value” (the default) but you could choose “Percentage”, “Text”, or “Visual”. You can read the details for those options on the “Help and Instructions” page.

  6. Dave says:

    What’s the best way to put a title before the list (e.g., Related Posts) and also center the links on the page?

    • David says:

      The best way to place a title before the list would be to place the title you want in the “Text and codes before the list:” field on the settings page.

      As for centering the links – that’s a matter of placing the codes and/or styles for centering in your settings. If you want to center the whole list I would recommend putting the centering code in “Text and codes before the list:” (with any necessary ending tags in the “Text and codes after the list:” field). If you want to just center the links you might want to place the necessary code in the “Output template:” field.

  7. AntonRSA says:

    Great plugin and it is so simple to use. I’m a coder myself and found it useful.

  8. Herb Border says:

    Thanks David — Lovely plug in and it is functioning well.

    However, just a simple question,

    Q: Is it possible to leave (ie: retain) the active page you are viewing — this dissapears from the list once you click on it.

    I would prefer it stays visible and changes colour to indicate it is ‘what you are currently looking at?

    Any help would be most appreciated.


    • David says:

      It would be possible. What’s happening is that when you click a link it opens the post for that link and then displays the similarity list for that link. (The similarity list for the new post will sometimes, but not always, include a link to the post you came from.) It would be easy enough to include the current post in the similarity list but I think what you are asking is for the similarity list of the post you came from to be displayed. I’m confident that this could be done, but it would take a fair bit of work to get there.

      • Herb Border says:

        Thanks for the prompt reply David.
        Ideally, it would be something like:

        Post 1
        Post 2
        Post 3
        Post 4

        Then, when you click on ‘Post 3’ for example, it would take you to that page AND remain on the menu choices… Understand this would be complicated, but though there might be a quick hack to keep the ‘active page’s’ title within the list…

        But, the effort you have gone to is fantastic nevertheless. Thanks again and good luck with the rest of your endeavors. Great Plugin.

        • David says:

          I can’t think of a quick hack to do that but I’ll keep that in mind for future development.

          Glad you like what I have done so far.

  9. Pingback: SEO – Point of view » Blog Archive » Wordpress SEO Plugins

  10. Maor says:

    The plugin look great, but I have one problem with it – it shows me also static pages while I want it to display only posts. Is there a way to limit it to posts only?
    More than that, is there a way to exclude certain categories from plugin’s scanning?


    • David says:

      The only way it should show pages is if you are using a plugin to add tags and/or categories to your pages. I could easily code Similarity to exclude those, but was not sure if it would make a difference. If you are interested in that change I can plan to include it in the next release. Excluding categories as likewise possible although I would have to make some decisions about how to handle that in the interface.

  11. Pingback: 10 WordPress plugins for a better blogging experience | Carol’s Vault – Best Freeware, Open Source Software

  12. Pingback: Top 1000 WordPress Plugin Authors « Metode de promovare

  13. Rocky says:

    Hi.. Great plugin!

    Can you expand on what do to when wanting to remove the ratings at the end of links, including the eyelashes? You mentioned to remove the “strength” references in the output file. I removed all of them in similarity.php as well as others, it either didn’t work or broke the site, I just revered to the original code and started tinkering again so no worries!

    Nice work BTW!

    Also…. ONE MORE SORRY…. Is it possible to override posts so they absolutely will show up in specific category posts? Like, I want about 5 articles to show up in CATEGORY A’s Posts but only there! And then 5 Others in CATEGORY B’s Posts.. etc etc…

    note that if there were two categories assigned, they’d both have to show up I’d imagine… Just a thought!

    Any way to do it?


    • David says:

      You should not need to go into the code to remove the “strength” references – just change the output template in the Similarity settings page. If you have a blank template the plugin defaults to “<li>{link} ({strength})</li>” If you like the format but want the strength to disappear just put “<li>{link}</li>” as the output template. (Removing all references to “strength” in the code would break some important parts of the plugin.)

      As for your second question – I’m not completely clear on what you are asking, but it could possibly be done by some very intrusive tag manipulation – I certainly don’t have any built in way to create some sort of super-association.

  14. Rocky says:


    Your reply on removing the strength was excellent. Thank you! I’m so used to changing code I didn’t even think that “Output Setting” was on the actual admin screen! heh…

    In regards to intrusive tag manipulation. Can you expand? And to clarify. I’m trying to have “Category A” show 5 specific related articles, while “Category B” through Z show their own 5 specific related articles. They would be “constants” instead of dynamic!

    Thank you VERY much,

  15. Rocky says:


    One more BIG question for you! And thank you again. Your work on this plugin is GRADE A. Is it possible to put the related links in the sidebar? If so, how? I’d imagine a line of code in the template would do it. Maybe working though another pluging that allows code in the sidebar! Which I do already have one installed!

    Thank you,

  16. David says:

    Upon further consideration the intrusive tag manipulation I hinted at would not work – the algorithm is specifically designed in a way that would not make that possible. I have some other ideas about how that could be accomplished through category templates – but that’s a completely different topic that has nothing to do with this plugin.

    As for putting the links in the sidebar – yes, that can be done and I have built lots of options as to how to do it. The easiest if you are comfortable altering your templates (and I suspect you are) would be to add the php call “<?php sim_by_tag(); ?>” into the place on your sidebar where you want the list to show. (You can use sim_by_cat or sim_by_mix if you prefer.) If you want it to show up somewhere in the middle of a sidebar that uses widgets you would have to use one of the shortcodes ([SIM-BY-TAG] for example). If your plugin allows for php calls then you could just use that to insert the php calls where you want with that.

  17. ActuRock says:

    hi and thanks for the plug 🙂
    I have a problem, I inserted this code in my pages.php file, it works when it has at least two relatives posts, but it doesn’t when it’s associated to only one post, why? should I change one parameter?

    example where the code works :

    and where it doesn’t work whereas it should :

  18. ActuRock says:

    In fact I realised that it didn’t take the last newsn only the olders one

  19. David says:

    I would be interested to know what you have set for “Minimum Match Strength” and it would help if you could explain what posts should be related to and how they should be connected.

  20. ActuRock says:

    the number is 0. Normally it should relate all the posts from here except the page
    thanks for helping

    • David says:

      Is one of those a page rather than a post? If so, do you have “Display Similarity on Pages” set to “Yes”?

      • ActuRock says:

        Here you have two results for the tag jimi hendrix first one is a page, the second one is a post, I only want to relate the post with the page, both of them have the tag jimi hendrix as attribute.

        Yes I set to “yes” the “display similiraty on pages”, but even if it’s no or yes, it doesn’t change anything

        • David says:

          Had “Display Similarity on Pages” been set to “No” it would have excluded the page and explained the lack of results – as it is, I will have to dig a little deeper to explain this behavior and solve the issue. Thanks for your patience and assistance.

  21. Gerhard says:

    The display format for similarity strength in the percentage format does
    not work in my Blog ( Only the “decimal format” appears, though I made the correct settings. Formerly it worked and I don’t know by which version this function get lost.

    • David says:

      Thanks for alerting me – I’ll look into that.

      • Gerhard says:

        Repeating my Post from December 29, 2009 at 3:11 am:
        The display format for similarity strength in the percentage format does
        not work in my Blog ( Only the “decimal format” appears, though I made the correct settings. Formerly it worked and I don’t know by which version this function get lost.

        • David says:

          I’m sorry Gerhard, I should have gotten back to you on that sooner. I’m using Version 2.13.2 of the plugin on WP 2.9.1 and the strength in percentage is working just fine. That code has not changed since I first implemented it. Try displaying strength as “Text” or “Visual” – if everything but percentage works then my best guess would be that another plugin or possibly your server or browser is taking the “%” as a special character and causing that display format to fail. If that’s the case we could write out “percent” if you are interested.

          • Gerhard says:

            After many updates in the meanwhile (all last versions), the percentage format doesn’t work yet. The other formats aren’t working too. by all settings always the decimal format (0.873) will be displayed. So I assume, that a new format (write out) “percent” won’t work too. Do you have another idea, where I could join on?

          • David says:

            I have been unable to duplicate your problem. I use the percentage format and it is working just fine. I’m not sure what might be interfering on your site.

          • Gerhard says:

            The problem I have described above does still exist with Version 2.13.2.
            Now I tried to go back to Similarity Version 2.12. on WordPress 3.3.1. and the strength in percentage is working again. The misfunction in 2.13.2. is reproducible with all the same settings.

            So my problem might be caused in some code-difference between your last versions.
            Per mail I will send you the printscreen of my settings.

            Do you have any idea?
            Thank you,

          • David says:

            I do not know what the problem is but this time I am able to reproduce it. I will look into this and release a new version once I figure out the solution.

            Thanks for bringing it to my attention.

  22. Pingback: Wordpress SEO Plugins | Cropix

  23. Hanna says:

    I’m sure I’ve done something wrong, but I can’t get any similar posts to show up — all my posts are unique…

    • David says:

      My first guess would be that you have set your minimum match strength too high on the Similarity Options page. Try setting it to “0” for starters and see if that gets things showing up.

      Beyond that I would have to know more about what your settings are to be more helpful.

      • Hanna says:

        Thanks for the reply, but it’s set to “0”.
        Other settings:
        Relative mixing weights: 1:1, no random post, no to auto-display list from function and don’t show Similarity on pages.

  24. Patrice says:

    By the way, I realised my problem was a website and tag problem on my website, not about your plugin

  25. Tux28 says:

    Thanks a lot for this plugin ! it works great !
    Good job !

  26. Li-An says:

    it seems the plugin shows pages in relative posts in WP 3.0
    See here by example:
    The first relative link is the About page.

  27. Ulrich SOSSOU says:

    The plugin was not displaying sub pages (only parent ones). WP 2.9
    So I had to comment out this code (line 658) :
    if ($wp_version > 2.5) {
    $query .= ” and post_parent = 0″;

  28. David says:

    Hi David

    Thanks for the great plugin, i am using on my site:


  29. Minter Dial says:

    Hi David

    I suspect it is because of the 3.0 version that it is not working for me, but would appreciate your advice… It is not showing up for me (see here: for example). Thanks, Minter

    • David says:

      I have been successfully using Similarity on 3.0 and 3.0.1 so whatever is not working it’s not version 3.

      Sorry I can’t be more helpful.

  30. Olive White says:

    Hi! Congratulations, i use it on my website and must admit this plugin gives the best relevant similar post results. I would like to enhance it via php, is it possible to add featured image to each similar post link? Thanks in advance.

    • David says:

      There is nothing currently to do post thumbnails although I’m sure it could be done. Unfortunately I don’t expect to have time to work on that myself in the near future.

      If anyone else were to get that working before I do I would be happy to include it in a future release.

  31. Cristian says:

    or need your help
    plugin “similarity” template works with Valid tags: {link}, {strength}, {url}, {title}
    as possible insert tags {content}
    and Limit Text Length?

  32. Antonio says:

    Hi, i’m Antonio and i’m from Italy. I like to know if it’s possible to limit text length of Link. I don’t know PHP, How can I truncate the link in PHP? Thanks Antonio

    • David says:

      Can it be done? Yes. Is Similarity built to do it currently? No.

      If you would like to edit the code yourself I could look at what changes you would have to make or if you can wait that sounds like a useful feature that I could push out in a new release in the near future.

Comments are closed.

Loading Facebook Comments ...