post-page

Contextual Related Posts in WordPress

62
responses
by
 
on
June 8th, 2004
in
Cool Scripts, WordPress Hack

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

Download the updated version of Contextual Related Posts.

heading
heading
62
Responses

 

Comments

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

  2. Mark says:

    Crap, it should be related_upgrade.php Sorry about that. Fixed.

  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.

  4. Mark says:

    Did you enable the plugin using the control panel?

  5. yep – actually it was enabled when I checked. I disabled and re-enabled it

  6. OK — all good … I had actually activated another plugin with a VERY similar name. works great!!

  7. Prashant says:

    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.

  8. Mark says:

    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.

  9. Prashant says:

    Mark, There might be some error in the SQL syntax with that statement. I get an SQL syntax error.

  10. Mark says:

    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;

  11. 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

  12. Billie says:

    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

  13. manuel says:

    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! 😉

  14. I like your’s plugin so much better than the one you said was more robust!

  15. chris says:

    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;

  16. Jane says:

    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!

  17. Marco says:

    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?

  18. rupi says:

    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!!!

  19. shane says:

    I have the same problem..

  20. Ash Haque says:

    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

  21. Matt says:

    We are getting the same error as #28. Any idea how to fix?

  22. Red Leader says:

    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

  23. Sojan says:

    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.

  24. hylton says:

    Same issue as #32. Anyone have answers?

  25. Diego says:

    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!

  26. Ryan Ward says:

    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,

  27. Mark Ghosh says:

    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

  28. Ryan Ward says:

    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?

  29. Ryan Ward says:

    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…

  30. sir jorge says:

    This plugin failed, tried everything i knew.

    Followed your instructions.

    It didn’t work.

  31. 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.

  32. Jack says:

    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!

  33. Megos says:

    Warning: preg_match() expects parameter 2 to be string, array given in //wp-content/themes/smashingtheme/index.php on line 32

    Anybody fixed this?

  34. Ben says:

    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.

  35. MauiDan says:

    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?

  36. MauiDan says:

    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();

    }

  37. muhibbuddin says:

    i got fatal error . bla bla bla. but i unsintall it. and my blog was clean now 🙂

  38. Even i’m getting the fatal error thing!! 🙁
    So i’m using the other related posts plugin now!
    Can anyone help me fixing this?

  39. Chuck says:

    Is there an updated version of this plugin? I’m running WP version 2.5.1

  40. uncleboob says:

    Here are some changes I made to the related_upgrade.php
    —-
    <?php
    /* 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 ADD FULLTEXT(post_content,post_title)”;
    $result = mysql_query($sql);

    if ($result)
    echo “Alter table successful, please proceed with instructions”;

    else
    echo “Something is amiss, please check instructions again.”;

    This one will work with WordPress 2.6.3 and hopefully above.

    Greetings



Trackbacks/Pingbacks

  1. […] /archives/2004/07/28/post-counter-and-most-visited-post-wordpress-12/ __Contextual links__

  2. 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…

  3. 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…

  4. […] site. Pour les utilisateurs de WordPress, c’est plein de solutions clé en mains, notamment celle-ci qui est très […]

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

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

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

  8. […] Related posts – lists 3 posts which are related to each post to enable readers to read more about a topic of […]

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

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

  11. […] Contextual Related Post – Show last 5 contextually related posts on single blog posts, increase exposure of previous written articles. […]

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

  13. […] Related Posts Plugin for WordPress HTML Plugin for WordPress […]

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

  15. […] -Related Posts, que presenta los posts relacionados al final de cada entrada. […]

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

  17. […] plugin es una modificacion de Related de Anne van Kesteren (Weblogtoolscollection). Descargate el plugin y sigue los siguientes paso de […]

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

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

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

Obviously Powered by WordPress. © 2003-2013

css.php