Similar Posts

Caveat

Unfortunately, due to ill-health, this plugin has not been developed or supported properly for some years. It works with the latest versions of WordPress (including on this website) but could possibly conflict with any WordPress features added after 2008 — e.g. custom post types — if you use them.

Purpose

This plugin displays a list of posts which are related or similar to the current post.

This is version 2.6.2.0 download latest version. It is compatible with WordPress 1.5–2.6.2.

  • 2.6.2.0 fixes a problem with stemming and stop words and offers a new fuzzy matching capability; supplies a .pot file making internationalisation possible; introduces the {imagealt} output tag and allows {excerpt} to output whole sentences; the content filter and the widget can now take a parameter string; output can be automatically placed after post content without editing theme files.
  • 2.6.1.2 fixes the German-language stemmer which should have been encoded as utf8.
  • 2.6.1.1 fixes the Italian-language stemmer which was crashing under PHP4.
  • 2.6.1.0 allows the current post to be marked manually where the automatic mechanism fails; when used as a widget the plugin now honours the setting to show nothing when there is no output; {commenterlink} now applies the appropriate WordPress filter; and fixed a problem with some installations not finding the right language files.
  • 2.6.0.1 fixes the option to include attachments and adds a parameter to the {imagesrc} output tag to append a suffix to the image name.
  • 2.5.0.11 has a new option to include posts which are attachments; a new output template tag {authorurl} which points to the archive of the author’s posts; new behaviour for the {php} output tag which can now accept other output tags in the code; and includes a fix for MySQL problems in some locales’.
  • 2.5.0.10 provides the ability to select from two algorithms for term extraction; allows you to specify post relationships by hand; and fixes a problem indexing tags in some languages.
  • 2.5.0.9 adds an option to match the current post’s author and extends the options for snippet and excerpt output tags to make the ‘more’ text into a link.
  • 2.5.0.8 adds an option to show posts by status, i.e., published/private/draft/future, changes the {categorynames} and {categorylinks} output tags by applying the ‘single_cat_name’ filter, and fixes a bug in WordPress pre-2.2 that stopped installation code running on Windows servers.
  • 2.5.0 improves the CJK matching algorithm by using bigrams. Also introduces a new output tag {imagesrc}, and adds more parameters to {image}. Fixes bugs with empty categories, excluded posts, and the option to omit current posts.
  • 2.5b28 improves the matching algorithm and adds an experimental mode for blogs in Chinese, Korean, or Japanese.
  • 2.5b27 fixes a bug with the bulk indexing of tags.
  • 2.5b25 makes some important changes: the {image} output tag now serves real thumbnails (couple of bug fixes too); output can now be sorted as you choose with sub-headings included; the {date:raw} tag modifier has been added to help the sorting; the ‘trim_before’ option has been replaced with the more logical ‘divider’.
  • 2.5b24 fixes to stop recursive replacement by content filter, {gravatar} to allow for ‘identicon’ etc., to {commenter} to allow trimming, and to remove a warning in safe mode
  • 2.5b23 brings a new option to filter on custom fields and adds proper nesting of braces in {if}.
  • 2.5b22 moves the manage menu under settings as a subpage, restores automatic indexing on activation, fixes conflicts with the legacy Similar Posts Feed plugin, fixes bugs in several output tags, and introduces the option to show only pages.
  • 2.5b20 doubles the speed of indexing and reduces the memory footprint considerably.
  • 2.5b19 fixes a bug when snippets are stripped of extra tags.
  • 2.5b18 fixes a problem with filtering the output and introduces the conditional tag {if:condition:yes:no}.
  • 2.5b16 fixes a problem with {php}.
  • 2.5b15 fixes for some more installation problems, one or two bugs, and adds the ‘included posts’ setting.
  • 2.5b14 fixes for some of the kinds of installation problems.
  • 2.5b11 fixes some widget problems.
  • 2.5b10 fixes (some?) of the problems folks have been having with no posts found. Most of such errors seem to arise when the proper table is not created and this version addresses that.
  • 2.5b9 has new features and improvements.
  • 2.3.6 restores the widgetiness I managed to remove in 2.3.5!
  • 2.3.5 has been rebuilt to save memory and can match the current post’s tags. It also fixes a bug with categories in WordPress < 2.3.
  • 2.3.4 now works as a widget.
  • 2.3.3 beta adds the ability to include as well as exclude categories and authors and is able to find posts by tag.
  • 2.3.2 beta fixes a conflict between tags and categories.
  • 2.3.1 beta fixes a stupid bug in category exclusion.
  • 2.3.0 beta is compatible with WP 2.3, fixes the {author} bug, and a number of problems related to versions of MySQL.
  • 2.1.1 beta fixes a badly chosen fallback value for the number of terms used to match similar posts.

Ideally, similarity or relatedness would be based on a post’s meaning. Tagging systems try to add meaning after the fact but suffer from two deficiencies, one practical and the other theoretical. When a blog already has many posts it can be impractical to retrofit a tagging system by tagging every post by hand. ‘Automatic’ services, like Yahoo’s, tend to produce too many suggestions which need to be culled, again by hand.

The theoretical problem with tagging is that it tries to pin down a meaning for a post by categorising it under a small number of types, whether those types belong to a predetermined hierarchy or arise by ‘folk’ classification. In fact, a post has a variety of meanings, a multitude of ways it can be related to other posts. Meaning doesn’t just lie in the intention of the author or in the classification of the reader; meaning also inhabits the text itself. Meaning is in the words.

The Similar Posts plugin compares posts by comparing their words. MySQL has a sophisticated full-text searching facility with a carefully tuned algorithm for judging the similarity between texts. Similar Posts extracts representative words from a post’s content, title, and tags and uses the full-text index to find the best matches between posts. This simple approach gives surprisingly good results.

The results can be tweaked in several ways to tailor them for you blog. By default the plugin chooses the 20 most frequent words to make its matches but the number is adjustable. It is worth experimenting to see how many words gives the best results for your blog — it has hardly any impact on speed, even if you set the value high enough to include the whole post. The relative importance given to words in your title may be adjusted so that well-chosen titles can be used to advantage or titles with little relevance downplayed. Similarly, tags can be used to improve matching or not according to your blog and it’s needs.

It is also possible to override the automatic similarity ranking by using a custom field. In the post edit screen create a custom field called ‘sp_similar’ with the ID value of the post to which you wish to ‘link’. You can link to multiple posts by entering a comma-delimited list of IDs.

The plugin has a settings page which lets you change how the output is generated and displayed. There is also a management page where you can change settings which affect the index.

Note: Similar Posts needs to know the ID of the post for which it is generating related posts. WordPress keeps track of that information in a global variable but unfortunately some other plugins can corrupt the data before Similar Posts gets a chance to use it. Similar Posts tries various tricks to get round this but sometimes it fails. The usual symptom is a list of similar posts that stays the same from page to page. You can help Similar Posts out by marking the current post manually by adding a line to your theme files. Find the place where the_content(); is used to display the current post and right after it put similar_posts_mark_current();.

Installation Instructions

  1. If upgrading from a previous version, first deactivate the plugin via the Plugins page and delete the plugin folder from your server.
  2. If you have been using the Similar Posts Feed plugin you should deactivate it as it is now obsolete.
  3. Upload the plugin folder to your /wp-content/plugins/ directory. You will also need to install the Post-Plugin Library.
  4. Go to your admin Plugins page and activate Similar Posts. This will automatically add a new table to enable fast, flexible full-text matching. If the plugin reports that there was a problem creating the table first try deactivating and reactivating the plugin.
  5. Put<!--?php similar_posts(); ?--> at the place in your theme files where you want the list of similar posts to appear. Lorelle on WordPress has a good guide to modifying themes for plugins.If you are averse to editing template files you can also place the post listing automatically either as a widget in the sidebar of your widget-aware theme or after each post (from the plugin’s Placement submenu).
  6. Use the admin Settings|Similar Posts pages to set all the available options. Alternatively, the options can be overridden by passing a parameter to the similar_posts template tag.

Usage and Options

The configuration page will help you to set up the plugin to your satisfaction.

The Index Management Page

Using this settings subpage you can re-index your blog. There are two main settings which affect the indexing.

PHP is, by default, not very good at handling text that isn’t in English and you might find Similar Posts mangles extended characters. If so, you can get the plugin to use PHP multi-byte string library if it is available.

The second setting attempts to handle words with related meanings. For example, ‘animal’ and ‘animals’ should probably not count as two distinct words, nor ‘follow’, ‘follows’, ‘following’, etc. You can choose to build the index using a stemming algorithm that groups such words as one (if there is one available for your language) or you can try the fuzzy matching algorithm. Whether it is better to be strict or to be relaxed will depend on your website.

A third setting is for blogs written mainly in Chinese, Korean, or Japanese. The MySQL fulltext index used by Similar Posts has problems with these languages but this setting tries several ways to work around the issues. The setting currently only works when posts are encoded as UTF-8. I would be very glad to get opinions from users familiar with these languages.

To avoid excessive memory use the indexing routine processes posts in batches of 100. This figure can be reduced to shrink the memory consumption even further.

Language Issues

The underlying MySQL full-text indexing is obviously very locale-dependent — how words are divided or punctuation handled, what words are treated as noise, etc. all vary from language to language. For the Similar Posts plugin to work well the version of MySQL on your server must be properly setup in the appropriate language.

Similar Posts generates the terms it matches on by analysing the word frequency of a post while ignoring the most common ‘noise’ words — in English, words like ‘of’, ‘and’, ‘across’, ‘someone’, etc. It uses a so-called ‘stop list’ of common English words to ignore. In fact it uses the stop list a standard English installation of MySQL uses. Obviously this list will be useless for other languages so Similar Posts makes the stop list pluggable.

The Similar_Posts folder contains a subfolder, ‘languages’, with stop lists and stemmers for a German, English, French, Spanish, and Italian. The plugin checks the WPLANG constant (defined in wp-config.php) to see which language WordPress is using and looks for a file on that basis. If WPLANG is undefined or the appropriate file cannot be found the default English list is used.

If you are looking for help setting up a stop list in a language other than English a good resource can be found at http://www.ranks.nl/stopwords. Stemmers in PHP are harder to come by. You can work out how to adapt any you find by inspecting the provided stemming files

414 replies on “Similar Posts”

  1. HI, I started using similar posts WP plugin. I think I installed it a long time ago, but I never added the: anywhere, and it worked fine, however now I want to move it, and I can’t find the: code. I’ve changed templated, etc. Did I put this in one of the ‘core’ wordpress php files? If so, where would I look now to find it. Any suggestions would be great. http://www.organicjar.com

  2. This plugin doesnt seem to work with WordPress 2.6.5:

    Plugin could not be activated because it triggered a fatal error.

    Warning: require_once(/home/mysite/public_html/wp-content/plugins/similar-posts/languages/en/stemmer.php) [function.require-once]: failed to open stream: No such file or directory in /home/mysite/public_html/wp-content/plugins/similar-posts/similar-posts.php on line 569

    Fatal error: require_once() [function.require]: Failed opening required ‘/home/mysite/public_html/wp-content/plugins/similar-posts/languages/en/stemmer.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/mysite/public_html/wp-content/plugins/similar-posts/similar-posts.php on line 569

  3. Still have the error:
    Fatal error: Call to undefined function ppl_display_limit() in /home/sites/blog4it.com/public_html/wp-content/plugins/similar-posts/similar-posts-admin.php on line 70

    I tried several versions, new and older, and it still there.

  4. when i change the $default_output_template=’..
    in similar-posts.php it dont have any effect on my website.. it still shows the {link] version, but i saved it correctly..

    i dont get it, i thought its a dreamweaver problem, but i downloaded the file on my local pc via ftp and there is nothing like {link} in the file.

    i refreshed my browser correctly.. any clue for me?

  5. Seems the Plugins are discontinued? There isn’t any feedback since early October and I have more problems than ever with WordPress 2.6.2 and 2.7.

    Always the same Similar Posts are shown and for Recent Posts and Recent Comments I can’t access the options pages anymore. (“Cannot load recent-posts.php” error and “Fatal error: Cannot redeclare recent_comments() (previously declared in …” error).

    What to do? Ahhhhh, Rob, come back please! 😉

  6. I’d like to add my voice to those looking to exclude certain terms from being used to match posts.

    In my case, I have a certain category in which I credit Hollywood Reporter and Variety as sources quite often. Because I do this, I’m sure those three words rank high in that category for matching–and as a result, they all tend to be similar to each other and only to each other because of those words.

    If I could just remove those three words from the equation, my similar posts showing up in that category would be a lot more relevant.

    Other than that, the thing’s been running like a caffeinated fever dream–my favorite kind. Thanks!

  7. I’m using WordPress as a CMS, and don’t want to use the word ‘posts’ in the heading.

    How can I change it from ‘Similar Posts’ to, eg ‘Related Articles’?

  8. I also have problems with similar-posts on WordPress 2.7 (excerpt doesn’t work), but it seems related to the the_excerpt() function template-function, which doesn’t work anymore on my site.
    Maybe it has something to do with other plugins, but I will keep looking into it, because simalar-posts is a very nice and especially configurable plugin !

  9. It’s thank a plugin developer day at WordPress…so…

    I wanted to give the developer of this similar posts plugin a big thank you. This plugin has been accurate in identifying similar posts and has greatly increase the length at which my users hand out at my blog and explore.

    We appreciate your hard work.

  10. Yes indeed Robert! You are an example to al plugins developers. Not only you have amazing plugins, but your support response was always incredible fast.
    Thank you very much!!!

  11. When I try the custom field {custom:thumbnail} to pull thumbnails it returns the location URL of the image instead of the image itself.
    What is wrong?

    Please help!

  12. Dimi, try this code to output your image:

    <img src="{custom:thumbnail}"/>

    and if you want the image to be linked to your post search result as well, try:

    <a href="{url}"><img src="{custom:thumbnail}"></a>

    Hope that helps

  13. Now that I played around with the series of Plugins- Similar post, Popular post, Recent post and Random post. I noticed a problem with compatability.

    It seems whenever This(these) Plugin scans the posts, other plugin such as smartyoutube or viper’s video quicktags will be unable to properly scan for their tag code within the post content and embed videos.

    Is there a get around for this?

  14. Quick addendum: removed the plugin using the plugin’s removal tool, deleted the plugin from the server, then reuploaded and reactivated it from scratch…and now every post is None Found. Well, at least there’s no line of demarcation any longer.

  15. hello, im using this plugin and i have a question.
    i want to use

    <?php $key = get_post_meta($post->ID,'key', true); ?>
    and
    <?php echo($key); ?>

    in my similar posts but i didnt really understood your explanation for {php} (sorry, im not american)

    could you please help me?

  16. I installed the plugin, and also library one that was mentioned to install. I placed the code: to the index, and I keep getting a fatal error:

    Fatal error: Call to undefined function: similar_posts() in /home/14822/domains/scene360.com/html/new/wp-content/themes/site/index.php on line 91

    My goal is to have a space with 6 recent posts of one category only, and this would include the actual images from the post too.

    What should I do to resolve the fatal error?

    Thank you for your time.

  17. Hi, I have wordpress version 2.7.1 and was using your Similar Posts plugin. Similar Posts 2.6.2.0

    Well I keep getting messages from my host about high CPU usage so I deactivated most of my plugins and am slow adding them back to see which one or ones is causing the high CPU usage. Well it looks like Similar Posts causes my load usage to go up. Have you any problem like that? I have deactivated it again and will try to activate it in a couple of days and check once more on the CPU usage.

    You say that you have used 60 WordPress plugins together? No problems with high CPU usage? What host are you with?

  18. When I deactivate this plugin my site is messed up (page doesn’t load all the way) and I still have the words, “Related Articles…” at the bottom of single posts. I tried looking in the theme files for, “recent_posts” (like you say to look for above, does that need updating?) but cannot find any assurance of it.

    I did look for and find the words, “Related Articles…” (which I guess I had added in) and I put in this code…

    if (function_exists('similar_posts')) { similar_posts(); }

    But all that did was put that code on my pages, but my pages did load OK this time. I also tried the code…

    <?php if (function_exists('similar_posts')) { similar_posts(); }

    But that make the page not able to load anything so I removed it.

    So when I try to reactive your plugin what code do I have to add to the single post file?

  19. i need to know how i would get a small line of text from that particular post under the link in the similar posts section to show up.

    like this:

    – the sky is falling and i can’t run away

    today the sky fell and i just can’t run away cause it…

  20. Okay, I finally, after lots of tinkering, found a series of settings that would get me back working again. Not sure why my old settings suddenly quit working, but regardless, the link on my name should take you to the blog post where I provide screenshots of what wound up working for me. Hope that helps some people.

  21. This plugin blows up when using FastCGI. I get an error:

    WordPress database error Incorrect string value: ‘/XE2 read…’ for column ‘content’ at row 1575 for query UPDATE wp_similar_posts SET content=”my stuff”…

    The post still goes through, but I get this annoying error message every time I post or update. Anyone have a clue?

  22. Hi,
    Congratulations for these awesome plugin !
    I’m trying to display the similar post inline but I can’t make it 🙁
    I’ve tried the CSS styles
    .similar-post ul {display: inline}
    or
    .similar-post ul li {display: inline}
    or
    .similar-post li {display: inline}

    any of these properties works
    can you please help me ?
    thxs a lot

  23. Hi … loving this (and the other) plugins! I am using {image} and would like the related images to show up on the same line (horizontally) rather than vertically up and down. Is this possible?

    Thanks so much!

  24. Duncan — As long as you want to continue using the first image in the post, you can easily adjust the size. Try this:

    {image:0:100:?::link}

    You can play around with the 100px to make the images larger or smaller depending on what you want. (You can remove the :link if you don’t want to image to be clickable.

    Hope that helps!

    Does anyone have any ideas about how to make the images display in a horizontal line rather than vertically? (See 2 comments up). THANKS!

  25. Kate — thanks so much for the comment. I appreciate the suggestion of that code and might use it… but my concern is the load time on resized full images, so accessing a thumbnail instead is the preferred solution if there is one out there!

    I was thinking about your horizontal line issue — at a guess, you could do an unordered list styled display:inline ? Something along those lines.

  26. Hi!

    First off, great plugin.

    Second, I’m having a problem with the settings page. The settings do not load for me. I see the main settings page with the sub pages such as General, Output, Filter, etc. But None of them contain any options.

    If I click on one, I see the title of the subpage and the save button, but nothing in between.

    The only one that works is Managing the Index, which I don’t really want to mess with anyway.

    On Report a Bug and Remove this plugin, I don’t see the title or the save/submit button.

    Any ideas?

    Cheers,
    Siam

  27. Hi!

    I had a compatibility problem with Similar Posts and WP-Email. After WP-Email successfully sends the e-mail, it shows the post again but without its content. Similar Posts then showed an SQL error because the post ID wasn’t set (“SELECT title, content, tags FROM wp_similar_posts WHERE pID= LIMIT 1”), like Rob in Denver (comment #66).

    I changed the function sp_terms_by_textrank() as you suggested to do with terms_to_match() and it now works fine.

    Can you verify if this workaround is correct and implement it on new versions?

Comments are closed.