6/8/2004 ↓

Contextual Related Posts in WordPress

Thanks for visiting! If you're new here, you may want to subscribe to our RSS feed. This blog posts regular Wordpress news, updates of themes, plugins, ideas, hacks, quick fixes and everything about blogging, especially about Wordpress. Go ahead, subscribe to our feed! You can also receive updates from this blog via email.

I had seen a couple of “Related Posts” implementations for WordPress and other blogs and they did not really make much sense to me. Once I had the code for contextual searches, the related posts plugin was a simple extension of that search code.

This plugin has the following features:
-related posts from your own blog, so more linkage
-extremely customizeable output
-links listed according to relevance
-”fuzzy” matching of posts/titles
-very easy install

You can see an implementation of this on this blog. Just click on the permalink of any entry and look for the titles at the bottom of the post content.

Download the plugin from here:
http://weblogtoolscollection.com/b2-img/related.zip

Please post bugs.

Looks like this has been done already, with much more robustness and versatility. Sorry for the late entry! :)

1 Star2 Stars3 Stars4 Stars5 Stars (21 votes, average: 4.19 out of 5)
Loading ... Loading ...

Friends

Translate

Translate to German Translate to Spanish Translate to French Translate to Italian Translate to Portuguese Translate to Japanese Translate to Korean Translate to Russian Translate to Chinese

Latest Videos

60 Comments | Leave a comment | Comments RSS

  1. I see no sign of search_upgrade… where would I find it?

    [Reply] Jonathan Greene (12 comments.) — 06/8/2004 @ 1:27 pm
  2. Crap, it should be related_upgrade.php Sorry about that. Fixed.

    [Reply] Mark (58 comments.) — 06/8/2004 @ 3:05 pm
  3. Closer…

    now I am getting :

    Fatal error: Call to undefined function: related() in /usr/www/users/jgreene/wp/index.php on line 77

    which is where I pasted your line from the readme.

    [Reply] Jonathan Greene (12 comments.) — 06/8/2004 @ 6:00 pm
  4. Did you enable the plugin using the control panel?

    [Reply] Mark (58 comments.) — 06/8/2004 @ 6:22 pm
  5. yep - actually it was enabled when I checked. I disabled and re-enabled it

    [Reply] Jonathan Greene (12 comments.) — 06/8/2004 @ 6:26 pm
  6. OK — all good … I had actually activated another plugin with a VERY similar name. works great!!

    [Reply] Jonathan Greene (12 comments.) — 06/8/2004 @ 8:03 pm
  7. Can this be setup to not display the name of the current post as the first in the list?

    Maybe if it could start the search at a post id before the current post, it could work.

    [Reply] Prashant (2 comments.) — 09/18/2004 @ 10:10 pm
  8. Sure. Just replace the sql in the hack with this one:

    $sql = "SELECT ID,post_title,post_content,post_excerpt,post_date, MATCH(post_title,post_content) AGAINST ('".$stuff."') AS score FROM ".$table_prefix."posts WHERE MATCH (post_title,post_content) AGAINST ('".$stuff."') AND ID <> “.$post->ID.” LIMIT 0,”.$max_related;

    and add $post to the globals list at the beginning of the function.

    [Reply] Mark (34 comments.) — 09/19/2004 @ 9:10 am
  9. Mark, There might be some error in the SQL syntax with that statement. I get an SQL syntax error.

    [Reply] Prashant (2 comments.) — 09/19/2004 @ 11:46 pm
  10. Prashant, This is what I have:

    global $wpdb, $table_prefix, $max_related, $post;
    $sql = "SELECT ID,post_title,post_content,post_excerpt,post_date, MATCH(post_title,post_content) AGAINST ('".$stuff."') AS score FROM
    ".$table_prefix."posts WHERE MATCH (post_title,post_content) AGAINST ('".$stuff."') AND ID <> “.$post->ID.” LIMIT 0,”.$max_related;

    [Reply] Mark (34 comments.) — 09/20/2004 @ 8:58 pm
  11. [...] /archives/2004/07/28/post-counter-and-most-visited-post-wordpress-12/ __Contextual links__ azeems blog » Hi — 10/13/2004 @ 9:28 am

  12. Wordpress Related Posts Plugin by Mark
    As you can see, I’ve installed this Contextual related posts plugin for wordpress by Mark… I can see it’s perfectly fetching out 5 realted posts when you check any pecific post through it’s permalink… but I’m still not sure about the criteria t…

    The iWorld — 11/5/2004 @ 10:34 am
  13. [...] s — By Vishal @ 9:32 am As you can see, I’ve installed this http://weblogtoolscollection.c.....wordpress/“>Contextual related posts plugin for wordpress by Mark [...]

    The iWorld » Wordpress Related Posts Plugin by Mark — 11/5/2004 @ 2:34 pm
  14. The code looks identical to the related posts plugin. What am i missing here?
    You can find the related posts plugin working on my site - blog.taragana.com

    [Reply] Angsuman Chakraborty (5 comments.) — 05/5/2005 @ 5:38 am
  15. having no success. I’d previously installed another Related Posts plugin which wasn’t working. I just installed yours but am getting this error on my page:
    Warning: preg_match() expects parameter 2 to be string, array given in /home/menpaper/public_html/wp-content/themes/journalized-winter/index.php on line 25

    [Reply] Billie (1 comments.) — 05/25/2005 @ 7:25 pm
  16. WordPress Related Posts

    I was reading some blogs today, and noticed that the “Related Posts” feature was actually quite handy. I found some related articles that I was actually interested in reading. With that in mind, I decided to add this feature to my blog. Th…

    Elliot Lee's Blog — 11/9/2005 @ 4:44 am
  17. mate, where do i change/edit the position of the “related posts” to show up?
    because right now it sits between the “write a comment” field and the actual comments.
    i want it either on top of that or below. makes sense, or?

    i just cant figure out where to edit this…
    have a look on my site where they show up and you get the idea :)

    and of cause, thanks for this great working plugin! ;)

    [Reply] manuel (1 comments.) — 12/9/2005 @ 12:02 pm
  18. I like your’s plugin so much better than the one you said was more robust!

    [Reply] hacker not cracker (1 comments.) — 03/22/2006 @ 1:04 am
  19. The above SQL fetches *everything* from the database, including drafts, private posts and static pages. I have modified the statement to only fetch published posts. You could also modify the WHERE post_status = ‘publish’ part to fetch both published posts and static pages: WHERE post_status IN {’publish’,’static’}.

    $sql = "SELECT ID, post_title, post_content, post_excerpt, post_date, post_status, MATCH(post_title,post_content) AGAINST ('".$stuff."') AS score FROM
    ".$table_prefix."posts WHERE post_status = 'publish' AND MATCH (post_title,post_content) AGAINST ('".$stuff."') AND ID ".$post->ID." LIMIT 0,".$max_related;

    [Reply] chris (1 comments.) — 06/16/2006 @ 4:36 am
  20. This is a cool idea and I’m about to implement it on my blog (dating site review). I think it will help visitors find more relevant info on a blog so come back more often - a really good idea!

    [Reply] Jane (1 comments.) — 10/31/2006 @ 10:35 am
  21. Hi!
    I am trying to set up this plugin but this is the message I get just after clicking on “Activate”: Warning: Cannot modify header information - headers already sent by (output started at /home/bianchim/public_html/wp-content/plugins/related.php:72) in /home/bianchim/public_html/wp-includes/pluggable-functions.php on line 269
    Afterall the plugin seems to work anyway, but then I cannot modify meta tags of new posts anymore.
    What’s wrong?

    [Reply] Marco (1 comments.) — 12/27/2006 @ 3:11 pm
  22. [...] site. Pour les utilisateurs de Wordpress, c’est plein de solutions clé en mains, notamment celle-ci qui est très [...]

    Gérant d’estrade » Blog Archive » Webmasters : aidez donc Google! — 04/18/2007 @ 1:38 pm
  23. Warning: mysql_connect() [function.mysql-connect]: Access denied for user ‘nobody’@'localhost’ (using password: NO) in /home/siteusrname/public_html/portal/related_upgrade.php on line 7
    Can’t connect to the database

    wht i fo now!!!

    [Reply] rupi — 04/23/2007 @ 10:22 am
  24. I have the same problem..

    [Reply] shane (2 comments.) — 06/2/2007 @ 2:41 am
  25. [...] Ghosh have upgraded and consolidated his old Contextual Related Posts Plugin for Wordpress. This new version (1.1) is a simple install (just install the plugin file) and it [...]

    Blogger’s Paradise » Blog Archive » WP Plugin: Contextual Related Posts — 06/5/2007 @ 8:12 am
  26. [...] especially with Wordpress. Go ahead, subscribe to our feed!I have upgraded and consolidated my old Contextual Related Posts Plugin for Wordpress. This new version (1.1) is a simple install (just install the plugin file) and it [...]

    Weblog Tools Collection » Blog Archive » WP Plugin: Contextual Related Posts — 06/5/2007 @ 8:33 am
  27. [...] and go back to the post to put the links in. On the other hand, WordPress has a plugin called Related Posts which uses MySQL’s full text search capabilities to find almost perfectly related posts [...]

    The Best Way to move from Blogger Beta to WordPress : Computer Tips From A Computer Guy — 06/24/2007 @ 10:45 pm
  28. I get this errror:

    Warning: main(wp-config.php) [function.main]: failed to open stream: No such file or directory in /home/sitename/public_html/directory/wp-content/plugins/related_upgrade.php on line 3

    Warning: main(wp-config.php) [function.main]: failed to open stream: No such file or directory in /home/sitename/public_html/directory/wp-content/plugins/related_upgrade.php on line 3

    Fatal error: main() [function.require]: Failed opening required ‘wp-config.php’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /home/sitename/public_html/directory/wp-content/plugins/related_upgrade.php on line 3

    [Reply] Ash Haque (1 comments.) — 07/9/2007 @ 5:20 am
  29. [...] Related posts - lists 3 posts which are related to each post to enable readers to read more about a topic of [...]

    Business Blog Boost » Blog Archive » Top ten Wordpress plugins for your blogs. — 07/9/2007 @ 6:02 am
  30. We are getting the same error as #28. Any idea how to fix?

    [Reply] Matt (1 comments.) — 07/10/2007 @ 7:23 pm
  31. [...] Related Posts Displays a list of posts related to the current post based on post context. (not exactly underrated or underused, but is the alternative to the above mentioned plugin) [...]

    Thirteen Completely Underrated Wordpress Plugins — 07/19/2007 @ 9:52 am
  32. I get the following error message after placing the sliver of code into my page. line 41 is the line where the code is entered. any advice?

    Warning: preg_match() expects parameter 2 to be string, array given in /home/heavytex/public_html/wp-content/themes/Heavytext/index.php on line 41

    [Reply] Red Leader (1 comments.) — 07/27/2007 @ 11:18 am
  33. I install this pluggin and it is fine, but it had a problem, it shows perfectly when i logined. But when i logout it not shows. I check and try many times, related posts shows only when i login to my site. Please help me to correct this problem.

    [Reply] Sojan (1 comments.) — 07/28/2007 @ 3:43 am
  34. [...] topic. Darren has said that in-post references to previous articles can be more effective than a plugin that points to related posts - however I have been tempted to try one of those [...]

    Blogging Challenge Ketchup | waxlyrical — 08/7/2007 @ 8:07 am
  35. Same issue as #32. Anyone have answers?

    [Reply] hylton (1 comments.) — 08/7/2007 @ 9:51 pm
  36. [...] Contextual Related Post - Show last 5 contextually related posts on single blog posts, increase exposure of previous written articles. [...]

    WP Plugins you don’t want to miss | Make Money Online — 08/27/2007 @ 10:40 pm
  37. [...] 5. Use a Related Posts plugin. Crosslinking to related posts on your blog helps with your internal linking, making keyword rich anchor text more prominent on your blog as well as helping your visitors navigate your site. Use a related posts plugin for WordPress like Contextual Related Posts. [...]

    SEO 101 Blogs and Feeds | Beginners tips on optimizing a blog and RSS feed — 08/28/2007 @ 7:34 pm
  38. [...] Related Posts Plugin for Wordpress HTML Plugin for Wordpress [...]

    SEO Friendly Wordpress Templates — 09/5/2007 @ 2:55 pm
  39. [...] the Contextual Related Posts plug-in. At the end of the post your readers will see links to posts that are related to that post. [...]

    Take the dust of your archive | Free Cash Quest — 09/11/2007 @ 11:27 pm
  40. hi, im getting this error:
    Warning: preg_match() expects parameter 2 to be string, array given in /home/content/d/i/e/diego018/html/wp-content/themes/sodelicious-black-10/single.php on line 49

    i need help! i really need this plugin!

    [Reply] Diego (1 comments.) — 09/11/2007 @ 11:52 pm
  41. [...] -Related Posts, que presenta los posts relacionados al final de cada entrada. [...]

    Actualizado a Wordpress 2.3.1 : EREBE — 11/3/2007 @ 3:56 pm
  42. I’m getting this error:

    Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) in /homepages/8/d196824117/htdocs/wordpress-testblog/related_upgrade.php on line 7
    Can’t connect to the database

    Any fix for this?

    Thanks,

    [Reply] Ryan Ward (3 comments.) — 11/25/2007 @ 10:42 am
  43. Ryan:
    In related_upgrade.php, Change
    $connexion = mysql_connect($server,$loginsql,$passsql) or die(”Can’t connect to the database
    “.mysql_error());
    To
    $connexion = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die(”Can’t connect to the database
    “.mysql_error());

    Hope that helps

    [Reply] Mark Ghosh (229 comments.) — 11/25/2007 @ 11:01 am
  44. Mark,

    Thank you, it helped, but, now I am getting this:

    Parse error: parse error, unexpected T_STRING in /homepages/8/d196824117/htdocs/wordpress-testblog/related_upgrade.php on line 7

    This is all prior to activating the plugin, correct?

    [Reply] Ryan Ward (3 comments.) — 11/25/2007 @ 11:12 am
  45. Actually, I changed the quotes and now it says “No Database Selected”.

    I then added DB_NAME and then I got another error and have removed it back to what your change was and it says “No database Selected”

    Any other suggestions…

    [Reply] Ryan Ward (3 comments.) — 11/25/2007 @ 11:42 am
  46. [...] and go back to the post to put the links in. On the other hand, WordPress has a plugin called Related Posts which uses MySQL’s full text search capabilities to find almost perfectly related posts [...]

    The Best Way to move from Blogger Beta to WordPress | Money,Rich For Your Live! — 12/15/2007 @ 2:30 pm
  47. This plugin failed, tried everything i knew.

    Followed your instructions.

    It didn’t work.

    [Reply] sir jorge (4 comments.) — 12/29/2007 @ 4:17 pm
  48. [...] plugin es una modificacion de Related de Anne van Kesteren (Weblogtoolscollection). Descargate el plugin y sigue los siguientes paso de [...]

    Plugin Post Relacionados — 01/2/2008 @ 12:01 am
  49. Hi
    I am getting hi, im getting this error:
    Warning: preg_match() expects parameter 2 to be string, array given …
    A couple people already wrote about it. Could it be bcs of the version number ?
    Thanks for the plugin.

    [Reply] Sherif Elsisi (2 comments.) — 01/27/2008 @ 10:59 pm
  50. [...] Contextual Related Posts Displaying a list of related posts is good for both your readers and helps spiders find your content (which has an SEO benefit). I’ve manually hacked the plug-in to also display related posts in your feed (also useful when you get scraped as it means more links back to you at least). There is also a related posts plug-in for your feed though I’ve not tried it. [...]

    New Blog Plug-In Check List » Self Made Minds — 02/6/2008 @ 8:51 am
  51. Hi, I followed your directions in comment 44 and now I’m getting the “No Database Selected” error like Ryan in comment 46.

    Can you help me?

    Thanks!

    [Reply] Jack (1 comments.) — 02/7/2008 @ 12:30 am
  52. Warning: preg_match() expects parameter 2 to be string, array given in //wp-content/themes/smashingtheme/index.php on line 32

    Anybody fixed this?

    [Reply] Megos (1 comments.) — 03/5/2008 @ 1:11 am
  53. thanks. I think I’ll just use the widget you use… it looks pretty easy. Doclix has a similar thing… it links certain relevant words on your page. I use it, it is cool. You or anyone who reads this post who blogs should check it out.

    [Reply] Ben (1 comments.) — 05/23/2008 @ 9:13 pm
  54. [...] Use a Related Posts plugin. Cross linking to related posts on your blog helps with your internal linking, making keyword rich anchor text more prominent on your blog as well as helping your visitors navigate your site. Use a related posts plugin for WordPress like Contextual Related Posts. [...]

    25 Blog Optimization Tips Even Dear Old Dad Could Ace (Plus 10 More Tips for Mom!) — 06/3/2008 @ 8:34 am
  55. Using echo mysql_error(); I was able to see the “something is amiss” error is:


    Something is amiss, please check instructions again.
    The used table type doesn't support FULLTEXT indexes

    Any ideas?

    [Reply] MauiDan (2 comments.) — 06/4/2008 @ 10:13 pm
  56. I’ve fixed the problem by altering the table type to MYISAM. Here is the complete code to do this:


    /* Don't remove this line. */
    require('wp-config.php');

    global $table_prefix;

    $connexion = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Can’t connect to the database".mysql_error());

    $dbconnexion = mysql_select_db(DB_NAME, $connexion);

    if (!$dbconnexion) {
    echo mysql_error();
    die();
    }

    $sql = "ALTER TABLE ".$table_prefix."posts ENGINE = MYISAM";
    $result = mysql_query($sql);

    if ($result) {
    echo "Alter table type successful...";

    } else {
    echo mysql_error();
    }

    $sql = "ALTER TABLE ".$table_prefix."posts ADD FULLTEXT(post_content,post_title)";
    $result = mysql_query($sql);

    if ($result) {
    echo "Alter table index successful, please proceed with instructions";
    } else {
    echo mysql_error();

    }

    [Reply] MauiDan (2 comments.) — 06/4/2008 @ 10:22 pm
  57. [...] visitors navigate around your site it also creates more keyword rich anchor text. A plug-in like Contextual Related Posts is a good one to use. After you download it follow the instructions [...]

    Use related posts plugin — 06/10/2008 @ 3:31 am
  58. i got fatal error . bla bla bla. but i unsintall it. and my blog was clean now :)

    [Reply] muhibbuddin (1 comments.) — 06/17/2008 @ 3:20 am
  59. Even i’m getting the fatal error thing!! :(
    So i’m using the other related posts plugin now!
    Can anyone help me fixing this?

    [Reply] Web Development (1 comments.) — 08/8/2008 @ 5:27 am

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

(required)

(required, will not be published)


S2