".mysql_error()); $dbconnexion = mysql_select_db(DB_NAME, $connexion); if (!$dbconnexion) { echo mysql_error(); die(); } $sql_run = 'ALTER TABLE `'.$table_prefix.'posts` ADD FULLTEXT `post_related` ( `post_name` ,' . ' `post_content` )'; $sql_result = mysql_query($sql_run); if ($sql_result) echo ("Congratulations! Full text index was created successfully!"); else echo (" Something went wrong. Please check the instructions on how to setup the full text index manually."); } } // End setup // Begin Related Posts #function related_posts($return_bool = false, $limit=5, $len=10, $before_title = '', $after_title = '', $before_post = '', $after_post = '', $show_pass_post = false, $show_excerpt = false) { function related_posts($limit, $len, $before_title, $after_title, $before_post, $after_post, $show_pass_post, $show_excerpt) { global $wpdb, $post; // Get option values from the options page if ($limit == "") { $limit = get_option('limit'); } if ($len == "") { $len = get_option('len'); } if ($before_title == "") { $before_title = stripslashes(get_option('before_title')); } if ($after_title == "") { $after_title = stripslashes(get_option('after_title')); } if ($before_post == "") { $before_post = stripslashes(get_option('before_post')); } if ($after_post == "") { $after_post = stripslashes(get_option('after_post')); } if ($show_pass_post == "") { $show_pass_post = get_option('show_pass_post'); } if ($show_excerpt == "") { $show_excerpt = get_option('show_excerpt'); } // Fetch keywords $postcustom = get_post_custom_values('keyword'); if (!empty($postcustom)) { $values = array_map('trim', $postcustom); $terms = implode($values, ' '); } else { $terms = str_replace('-', ' ', $post->post_name); } // Make sure the post is not from the future $time_difference = get_settings('gmt_offset'); $now = gmdate("Y-m-d H:i:s",(time()+($time_difference*3600))); if (!$limit) $limit = '0,3'; // Quick fix for "no defaults" bug 28.9 // Primary SQL query $sql = "SELECT ID, post_title, post_content," . "MATCH (post_name, post_content) " . "AGAINST ('$terms') AS score " . "FROM $wpdb->posts WHERE " . "MATCH (post_name, post_content) " . "AGAINST ('$terms') " . "AND post_date <= '$now' " . "AND (post_status IN ( 'publish', 'static' ) && ID != '$post->ID') "; if ($show_pass_post=='false') { $sql .= "AND post_password ='' "; } $sql .= "ORDER BY score DESC LIMIT $limit"; $results = $wpdb->get_results($sql); $output = ''; if ($results) { if($return_bool) { return true; } else { foreach ($results as $result) { $title = stripslashes(apply_filters('the_title', $result->post_title)); $permalink = get_permalink($result->ID); $post_content = strip_tags($result->post_content); $post_content = stripslashes($post_content); $output .= $before_title .'' . $title . '' . $after_title; if ($show_excerpt=='true') { $ze = substr($post_content, 0, $len); $ze = substr($ze, 0, strrpos($ze,'')); $ze = $ze . '...'; $output .= $before_post . $ze . $after_post; // $words=split(" ",$post_content); // $post_strip = join(" ", array_slice($words,0,$len)); // $output .= $before_post . $post_strip . $after_post; } } return $output; } } else { if($return_bool) { return false; } else { return 'No related posts'; } } } function related_posts_exist() { return related_posts(true); } // End Related Posts // Begin Keywords function find_keywords($id) { global $wpdb; $content = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE ID = '$id'"); if (preg_match_all('//i', $content, $matches, PREG_SET_ORDER)) { $test = $wpdb->get_var("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = '$id' AND meta_key = 'keyword'"); if (!empty($test)) { $output = explode(' ', $test); } else { $output = array(); } foreach($matches as $match) { $output = array_merge($output, explode(' ', $match[1])); } $output = array_unique($output); $keywords = implode(' ', $output); if (!empty($test)) { $results= $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '$keywords' WHERE post_id = '$id' AND meta_key = 'keyword'"); } else { $results = $wpdb->query("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value) VALUES ('$id', 'keyword', '$keywords')"); } $content = format_to_post(balanceTags(preg_replace("//i", "", $content))); $content = str_replace("'", "'", $content); // Fix for ' in $content $results = $wpdb->query("UPDATE $wpdb->posts SET post_content = '$content' WHERE ID = '$id'"); } return $id; } // End Keywords // Begin Related Posts Options function rp_subpanel() { if (isset($_POST['update_rp'])) { $option_limit = $_POST['limit']; $option_len = $_POST['len']; $option_before_title = $_POST['before_title']; $option_after_title = $_POST['after_title']; $option_before_post = $_POST['before_post']; $option_after_post = $_POST['after_post']; $option_show_pass_post = $_POST['show_pass_post']; $option_show_excerpt = $_POST['show_excerpt']; update_option('limit', $option_limit); update_option('len', $option_len); update_option('before_title', $option_before_title); update_option('after_title', $option_after_title); update_option('before_post', $option_before_post); update_option('after_post', $option_after_post); update_option('show_pass_post', $option_show_pass_post); update_option('show_excerpt', $option_show_excerpt); ?>
Options saved!
If this is your first time installing this plugin you will have to run this script (opens a new window) in order to create the index table required by the plugin. If this fails, please refer to the readme on how to create it manually.