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.
I see no sign of search_upgrade… where would I find it?
Crap, it should be related_upgrade.php Sorry about that. Fixed.
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.
Did you enable the plugin using the control panel?
yep – actually it was enabled when I checked. I disabled and re-enabled it
OK — all good … I had actually activated another plugin with a VERY similar name. works great!!
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.
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.
Mark, There might be some error in the SQL syntax with that statement. I get an SQL syntax error.
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;
>
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
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
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! 😉
I like your’s plugin so much better than the one you said was more robust!
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;
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!
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?
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!!!
I have the same problem..
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
We are getting the same error as #28. Any idea how to fix?
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
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.
Same issue as #32. Anyone have answers?
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!
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,
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
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?
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…
This plugin failed, tried everything i knew.
Followed your instructions.
It didn’t work.
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.
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!
Warning: preg_match() expects parameter 2 to be string, array given in //wp-content/themes/smashingtheme/index.php on line 32
Anybody fixed this?
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.
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?
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();
}
i got fatal error . bla bla bla. but i unsintall it. and my blog was clean now 🙂
Even i’m getting the fatal error thing!! 🙁
So i’m using the other related posts plugin now!
Can anyone help me fixing this?
Is there an updated version of this plugin? I’m running WP version 2.5.1
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