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 will show the last 5 related posts from your blog. The display show the links right after the comment form. The matching is done with the post title of the post being viewed. Examples include my Green Car Blog (wordpress 2.0) and Desi Dalal (WordPress 1.5)
PS: Some theme authors tend to remove default actions from their themes (Rin is a good example). If you are having problems displaying the related posts, please check with your theme author or post a comment here for help.
Download Contextual Related Posts Plugin
Download the updated version of Contextual Related Posts.
Fantastic! Works great with WP 1.5.2 and K2 Beta One 96. You have given new life to old posts with a renewed relevance. Thanks!
Uh-Oh! This Plugin will find unpublished pending posts in your WRITE queue and display them. That’s not good. Uninstalled the Plugin.
Good call David. Fixed in the download.
Woo-hoo! Fixed! All Fantoosticness has been restored. Thanks, Mark!
Wow ! That’s a very good plugin Mark, thank you đ
Just a quick question though : the comment LivePreview appears before the Related posts section. Is there a way to change that ?
Thanks
Thanks for a great plugin! Just one question: I’m using another plugin which auto-closes comments after x days. For all posts where the comments are closed, there are no contextual related posts listed. Is there a way around this?
Not in this version of the plugin since it uses the comment code to start off the display. You can add the code to your template to get around the display problem.
Hey Mark?
It looks like the first return of the five is always the title of the article you’re reading. Does that seem like a wasted return to you? Is it possible for your Plugin to ignore the title of the originating post so it is never returned in its own Context?
Try it now. đ
Ooo! Perfecto! That’s good stuff, thanks Mark! Don’t you think these changes deserve a change in version number?
Not really. These are point releases at most, not really deserving of major structural changes.
WordPress 2.0? Did I hear that right?
Is there any difference between this and the WP Related Entries from w-a-s-a-b-i?
excellent plugin, i’ve been wanting something like this.
how do you change where the items display?
Hello,
Great plug in that gives a second life to forgotten posts.
What would be great would be the ability to search posts with the same tags (UltimatTagWarrior tagging system)
Luc
How do I move the related entry to the top instead of below the coment form?
I really wanted this plugin to work on my blog. However, after installing it, this is what I got:
WordPress database error: [The used table type doesn’t support FULLTEXT indexes]
SELECT ID,post_title,post_content,post_excerpt,post_date, MATCH(post_title,post_content) AGAINST (‘The Bush Iraq Strategy’) AS score FROM wp_posts WHERE MATCH (post_title,post_content) AGAINST (‘The Bush Iraq Strategy’) and post_status = ‘publish’ and id 162 LIMIT 0,5
Am I dead in the water?
hey thanks for making this plugin. i’ve been troubleshooting the one from w-a-s-a-b-i and when I installed this, it did exactly what i needed.
Ok what is the hint in moving the Related Posts above the comments.
I’ll echo the last few commentors: This very page has the related posts above the comments, but the plug-in, with its ad_action hook, only appears below the comment form. How can the related posts display appear at the bottom of the post as you have it?
Does this works in pages as well? đ
Very good, thanks!
I’ve tweked the queries to also add the `post_excerpt` field to the fulltext index and then to use to find similar matches.
Hi Stoyan, how did you tweak the queries to add post excerpt? If I have technorati tags, is there some way I could have the posts “related”?
Thanks!
A few of us want to move the posts above the comments, but no one has helped to answer how to do this. Any help would be great. Thanks.
hi, sorry for my english, i’m french and i don’t speak english đ
I try to use your plugin on my website, with Fluid Solution skin.
But that does not function. I install plugin, but it don’t copy script in my skin (single.php), it’s ok with default skin. can you try to help me please… ?
Will it work for WordPress 2.1?
to Pariah S. Burke AND Josh :
i found a way to solve this problem,
first:remove the code “add_action(‘comment_form’,’related’);” from
related.php
second:add “” above the comment form code in
the single.php file(you can find this file from your current theme files)
sorry for my poor english.
second:add
""
above the comment form code inthe single.php file(you can find this file from your current theme files)
For those of you who still want to move the Related Posts section above the comments, first remove the
add_action(ĂąâŹâącomment_formĂąâŹâą,’relatedĂąâŹâą);
from the plugin code. Then add,
to the single post code in your theme–wherever you want the Related Posts section to show up. Personally, I put mine right below the code for my adsense.
Sorry you should add this,
to the single post code
Okay it won’t show up…but with the less than greater than brackets around it insert
?php related(5); ?
into your code.
I like the ease of the plugin, but the first related post duplicates the post it appears on. Is there a fix around this? This seems like a major bug. A post shouldn’t be related to itself. Help? I did a side-by-side comparison test on my blog of this contextual posts plugin with the wasabi plugin.
Tom,
No problem. Look for the following line:
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
And add the following after it:
global $wp_query;
$temppostid = $wp_query->post->ID;
Hi, Mark,
I’m really liking the plugin so far, but something I’d like to accomplish is to prevent static pages and tags from showing up in the list. Is there a way to eliminate these from the query that you could offer?
Thank you for your time!
Daniel:
Here’s how to prevent pages from appearing in the list, at least with WP 2.2. Add the following to the SQL query after post_status = ‘publish’ :
and post_type = ‘post’
And a correction to Neal’s comment about adding a call to related directly in a theme’s single.php file. The correct statement to add is:
<?php if (function_exists(‘related’)) related($post->ID); ?>
Thank you for the heads-up, Bob. I’ll give the new query a go, and also check my template for the modified line you’re mentioning here as well.
I really dig this plugin! Thanks Mark!
I noticed you placed yours in the same location that I did after the post. I’m beginning to wonder if perhaps manual insertion should be stressed more with this plugin as opposed to the automatic insertion it currently has – after the Comments section. It seems to work out better manually.
Awesome. That totally did the trick! Thank you kindly, Bob.
The problem with the automatic insertion is that it only works if the comment form is displayed. It’s possible to make it also work if comments are closed (which would require a change to my theme anyway), but I don’t think WP has any built-in hooks for the case where users have to login to make comments. Also, Neal’s error was passing the number of links to create, but the function really needs the post ID (so it doesn’t display a link to itself). And the call to function_exists allows you to deactivate the plugin without having to edit the theme again.
I also noticed that the plugin creates bad HTML if there aren’t any related posts; an extra </ul> is created. But I don’t want anything to be displayed if there aren’t any related posts, so I rewrote that portion of the code. Here’s the revised function, with the revised SQL query I posted earlier; otherwise, all the changes I made are after the query:
function related($temppostid='') {
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
if ($single && $post->post_title != "") {
$stuff = addslashes($post->post_title);
$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 post_status = 'publish' and post_type = 'post' and id $temppostid LIMIT 0,$max_related";
$searches = $wpdb->get_results($sql);
if($searches){
echo "$RelatedText\n";
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo "ID) . "\" rel=\"bookmark\">$title\n";
} //end of foreach loop
echo "\n";
}
}
}
Blah… Even though I posted with the <code> tag, the site messed-up the code. Give me a few minutes to change all the less than and greater than symbols and try again. It also got rid of the indenting, but I don’t think I can fix that.
OK, let’s try posting the function again:
function related($temppostid=”) {
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
if ($single && $post->post_title != “”) {
$stuff = addslashes($post->post_title);
$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 post_status = ‘publish’ and post_type = ‘post’ and id <> $temppostid LIMIT 0,$max_related”;
$searches = $wpdb->get_results($sql);
if($searches){
echo “<div class=\”related_posts\”>$RelatedText<ul>\n”;
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo “<li><a href=\”” . get_permalink($search->ID) . “\” rel=\”bookmark\”>$title</a></li>\n”;
} //end of foreach loop
echo “</ul></div>\n”;
}
}
}
Bob,
Thanks for your code. I have added that to the post to preserve formatting.
Bob,
I tried the code you suggested above – and it takes care of the XHTML invalid formatting ‘problem’ with the added tag. The problem I have though, is that I lose the ‘No results found.’ display – which I would rather keep for layout consistancy.
I’m assuming there should be a way to wrap both separately as functions – then running through the main loop to determine which one to echo out? I attempted where I thought an else statement could occur – but the attempts caused errors (been a while since I’ve had a PHP hat on).
I prefer not to have the no results. But if you want it, you could keep the original code (with a minor bug that browsers would ignore), or you can try the following UNTESTED code. It’s the part after the SQL query is created:
$searches = $wpdb->get_results($sql);
echo “<div class=\”related_posts\”>$RelatedText”;
if($searches){
echo “<ul>\n”;
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo “<li><a href=\”” . get_permalink($search->ID) . “\” rel=\”bookmark\”>$title</a></li>\n”;
} //end of foreach loop
echo “</ul>”;
}
else{
echo “<br /> <br />No results\n”;
}
echo “</div>\n”;
}
}
I tried something similar to that, but I can see if there’s something different in your placement of the else statement and echoing the div tag, to see if that’s do-able. Otherwise, I’m thinking this would have to be wrapped in two functions.
Well, I think this is now officially a perfect plugin! Thanks to Bob for his help! I’ve included the code of my final – to re-include the ‘No Results.’ message if nothing is found.:
function related($temppostid=”) {
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
if ($single && $post->post_title != “”) {
$stuff = addslashes($post->post_title);
$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 post_status = ‘publish’ and post_type = ‘post’ and id $temppostid LIMIT 0,$max_related”;
$searches = $wpdb->get_results($sql);
if($searches){
echo “$RelatedText\n”;
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo “ID) . “\” rel=\”bookmark\”>$title\n”;
} //end of foreach loop
echo “\n”;
} else {
if ($search_counter $RelatedText\nNo results.\n\n”;
}
}
}
}
Sorry, I had included a comment for the $search++; string, which I wanted to note also appears to work without that line. (Possibly delete the comment above to eliminate confusion.):
function related($temppostid=”) {
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
if ($single && $post->post_title != “”) {
$stuff = addslashes($post->post_title);
$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 post_status = ‘publish’ and post_type = ‘post’ and id $temppostid LIMIT 0,$max_related”;
$searches = $wpdb->get_results($sql);
if($searches){
echo “$RelatedText\n”;
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo “ID) . “\” rel=\”bookmark\”>$title\n”;
} //end of foreach loop
echo “\n”;
} else {
if ($search_counter $RelatedText\nNo results.\n\n”;
}
}
}
}
Well, this site’s rules don’t appear to like the code. Message me through my site if you’re interested, I guess.
You have to change all the < symbols to < (don’t forget the “;”) and > to > then post it.
function related($temppostid=”) {
global $wpdb, $table_prefix, $max_related, $post, $RelatedText, $single;
if ($single && $post->post_title != “”) {
$stuff = addslashes($post->post_title);
$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 post_status = ‘publish’ and post_type = ‘post’ and id <> $temppostid LIMIT 0,$max_related”;
$searches = $wpdb->get_results($sql);
if($searches){
echo “<div class=\”related_posts\”>$RelatedText<ul>\n”;
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
echo “<li><a href=\”” . get_permalink($search->ID) . “\” rel=\”bookmark\”>$title</a></li>\n”;
} //end of foreach loop
echo “</ul></div>\n”;
} else {
if ($search_counter <= $max_related) {
$search_counter++;
echo “<div class=\”related_posts\”>$RelatedText\n<p>No results.</p>\n</div>\n”;
}
}
}
}
That worked. Sorry, Mark. I think I cluttered up this comment thread a little. (Might want to delete the non-relevent stuff.)
No problem Daniel. Thanks for the fix. I will leave the comments there for posterity.
I translated all the notes and text to spanish, how do I get it to you so you can offer a spanish verison? (contact my mail if you are interested)
Hey Mark,
mark I was going through this wordpress plugin looking for a way to move my related post above the comments. And saw in the threads that it was being address. I replaced some the code with commenter 62. Daniels suggested code then I went into the actual single page view to place the function:
php if (function_exists(ârelatedâ)) related($post->ID);
where I wanted to see my comment displayed and when I accessed a single post, but the area that needes to load “Related Post” loads nothing. Although everything else loads fine. any idea what that could be
Here is the code for the plugin
http://rafb.net/p/DPv5xC73.html
Here is the code for the actual single.php page
http://rafb.net/p/XOBxgf16.html
Sean,
It’s difficult to tell what the problem is without a working example provided. The code appears fine, aside from the possibility that you may want to wrap the php line in a div with an id, and style accordingly.
Daniel: I dont know what happened but I deactivated the plugin deleted the file. then I downloaded the file again and uploaded that to the server and added the ? if functions_exists() code again. and it works: But what I did notice was THE WAY THE CODE IS COPIED. the single and double quotes dont seem to copy over correctly. so if anyone else runs into this problem just go in and manually replace the single and double quotes again, that should do the trick.
I’m getting some of the posts as double listed.
Sean,
The problem was probably as you describe it – relating to the double-quotes. It’s a common issue when copying anything from a WordPress rendered page, and should always be double-checked prior to running code.
I’ve installed the plugin, but the text is far too small and almost unnoticeable. Look at this post
http://nflminute.com/2007/07/0.....odes-down/
to see what I mean. Any suggestions?
You should be able to style the text from the plugin. If you have a style in mind, email me the code and your plugin and I will add it.
Forgive my lack of knowledge. All I’d like to do is make the text bigger, similar in size to other text on the page. Is there a quick fix to do that?
I tried to implement the code which Daniel provided ID); ?> to have the related posts above the comment form but nothing shows up. I’m using wordpress 2.2. Can someone tell me how can I have the related posts above the comment part?
Mark i got the error as below
WordPress database error: [The used table type doesn’t support FULLTEXT indexes]
SELECT ID,post_title,post_content,post_excerpt,post_date, MATCH(post_title,post_content) AGAINST (‘Using permalinks option of wordpress in IIS (windows server)’) AS score FROM mainposts WHERE MATCH (post_title,post_content) AGAINST (‘Using permalinks option of wordpress in IIS (windows server)’) and post_status = ‘publish’ and id 6 LIMIT 0,5
Related Posts from the Past:
No results.
[…] Madhujit Ghosh’s Contextual Related Posts […]
HI.HOw can i chanage the contextual-related-posts space? for example:
below the coment…..thank you
http://www.china-club.net
Thank goodness! It works. I tried tons of differant ones but this one actually worked just ftp it up and activate. Displays great, looks great! Thankyou.
Cool plugin! How replace “related-posts” below the “comments” ?
I don`t have single.php in my theme.
Megos,
The theme you’re using does not include the appropriate header comments in order to show-up in the Theme Editor. You might want to send a note to that theme author to request including the proper header comments. Otherwise, you’ll have to edit that file in your text editor, and then upload it to your site via FTP. (Save a back-up of your original!)
I don`t now how contact with theme author. Can You say how can I edit relative.php for this? Or can You edit relative.php? Post Relative v2… đ
Megos,
Your theme author is linked at the bottom of every page of your Web site, in the footer. The theme author’s Contact page is the following:
http://www.designdisease.com/contact/
It`s not for this site.
I’m not sure how to help you here then.
hiya there, i just wanted to ask if this plugin will still work for WP 2.3 đ
thx for you patience
Kim đ
No problems to report here, Kim. I upgraded to 2.3 a week ago, and since this morning, 2.3.1.
This worked great first time! Thank you.
I struggled with moving the related posts above the comments, but I’m a noob. Eventually figured it out.
Good learning lesson for me.
Thanks again for provide this easy plug-in.
Thanks for the great plugin! I use it on all of my blogs.
I’m glad you build such simple-to-use plugin. This is really what I’m looking for, I have tried similar plugins but unfortunately they have the user to enter mysql database which not everyone could handle.
Thanks again!
Could somebody post the code for putting the “related posts” somewhere else? I tried the suggestions above, but they don’t work. The text “add_action…” just shows up. Thanks.
ANybody notice the google ad at the top of the page???
“Rocket your traffic with text link ads $100 free text link ads”
This is probably a stupid question, but what do I do if the SQL Index Table Setup fails? It says to refer to a readme, but I don’t see one.
Somebody help the techtard?
Hey…I am getting this error – WordPress database error The used table type doesn’t support FULLTEXT indexes for query ALTER TABLE wp_posts ADD FULLTEXT(post_content,post_title) made by include.
How to reslove it?
So, this is a really, really stuupid question … how do i install it=?
This is an Awesome plug in, installed it on my site with no problems