File: /home/httpd/html/stoptube.com/wp-content/plugins/related.php
<?php
/*
Plugin Name: Contextual Related Posts
Version: 1.1
Plugin URI: http://weblogtoolscollection.com/
Description: Show last 5 contextually related posts on single blog posts, increase exposure
Author: Mark Ghosh (LaughingLizard)
Author URI: http://weblogtoolscollection.com
Copyright (c) 2004
Released under the GPL license
http://www.gnu.org/licenses/gpl.txt
This file is part of WordPress.
WordPress is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
INSTALL:
Just install the plugin in your blog and activate
*/
$max_related = 5; //Change this to show maximum related links
$RelatedText = "<h2>Related Posts from the Past:</h2>"; // THis is displayed before the related posts
// Make sure that the plugin is installed, if not, create the tables
$RelatedPosts = get_option('RelatedPosts');
if ($RelatedPosts == '') {
global $table_prefix;
$sql = "ALTER TABLE ".$table_prefix."posts ADD FULLTEXT(post_content,post_title)";
$wpdb->query($sql);
update_option('RelatedPosts', "RelatedPostsver11");
}
add_action('comment_form','related');
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 id <> $temppostid LIMIT 0,$max_related";
$search_counter = 0;
$searches = $wpdb->get_results($sql);
echo '<div>'.$RelatedText;
if($searches){
echo "<ul>";
foreach($searches as $search){
$title = trim(stripslashes($search->post_title));
if ($search_counter <= $max_related) { ?>
<li><a href="<?php echo get_permalink($search->ID);?>" rel="bookmark"><?php echo $title;?></a></li>
<?php } //end of search_counter loop
$search_counter++; } //end of foreach loop
}else{
echo "<p>No results.</p>";
}
echo '</ul></div><br/><br/>';
}
}
?>