ID;
$cats = $wpdb->get_results($q);
foreach(($cats) as $cat) {
if (in_array($cat->term_id, $exclude) != false){
return;
}
}
}
if(!$post->ID){return;}
$now = current_time('mysql', 1);
$tags = wp_get_post_tags($post->ID);
$taglist = "'" . $tags[0]->term_id. "'";
$tagcount = count($tags);
if ($tagcount > 1) {
for ($i = 1; $i < $tagcount; $i++) {
$taglist = $taglist . ", '" . $tags[$i]->term_id . "'";
}
}
$limit = $wp_rp["wp_rp_limit"];
if ($limit) {
$limitclause = "LIMIT $limit";
} else {
$limitclause = "LIMIT 10";
}
$q = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM $wpdb->term_taxonomy t_t, $wpdb->term_relationships t_r, $wpdb->posts p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id = p.ID AND (t_t.term_id IN ($taglist)) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < '$now' GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC $limitclause;";
$related_posts = $wpdb->get_results($q);
$output = "";
if (!$related_posts){
$wp_no_rp = $wp_rp["wp_no_rp"];
$wp_no_rp_text = $wp_rp["wp_no_rp_text"];
if(!$wp_no_rp || ($wp_no_rp == "popularity" && !function_exists('akpc_most_popular'))) $wp_no_rp = "text";
if($wp_no_rp == "text"){
if(!$wp_no_rp_text) $wp_no_rp_text= __("No Related Post",'wp_related_posts');
$output .= '
'.$wp_no_rp_text .'';
} else{
if($wp_no_rp == "random"){
if(!$wp_no_rp_text) $wp_no_rp_text= __("Random Posts",'wp_related_posts');
$related_posts = wp_get_random_posts($limitclause);
} elseif($wp_no_rp == "commented"){
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Commented Posts",'wp_related_posts');
$related_posts = wp_get_most_commented_posts($limitclause);
} elseif($wp_no_rp == "popularity"){
if(!$wp_no_rp_text) $wp_no_rp_text= __("Most Popular Posts",'wp_related_posts');
$related_posts = wp_get_most_popular_posts($limitclause);
}
$wp_rp_title = $wp_no_rp_text;
}
}
foreach ($related_posts as $related_post ){
$output .= '';
if ($wp_rp["wp_rp_thumbnail"]){
$output .= '
';
}
if ((!$wp_rp["wp_rp_thumbnail"])||($wp_rp["wp_rp_thumbnail"] && $wp_rp["wp_rp_thumbnail_text"])){
if ($wp_rp["wp_rp_date"]){
$dateformat = get_option('date_format');
$output .= mysql2date($dateformat, $related_post->post_date) . " -- ";
}
$output .= ''.wptexturize($related_post->post_title).'';
if ($wp_rp["wp_rp_comments"]){
$output .= " (" . $related_post->comment_count . ")";
}
if ($wp_rp["wp_rp_except"]){
$wp_rp_except_number = trim($wp_rp["wp_rp_except_number"]);
if(!$wp_rp_except_number) $wp_rp_except_number = 200;
if($related_post->post_excerpt){
$output .= '
'.(mb_substr(strip_tags($related_post->post_excerpt),0,$wp_rp_except_number)).'...';
}else{
$output .= '
'.(mb_substr(strip_tags($related_post->post_content),0,$wp_rp_except_number)).'...';
}
}
}
$output .= '';
}
$output = '';
$wp_rp_title_tag = $wp_rp["wp_rp_title_tag"];
if($before_title){
if($wp_rp_title != '') $output = $before_title.$wp_rp_title .$after_title. $output;
}else{
if(!$wp_rp_title_tag) $wp_rp_title_tag ='h3';
if($wp_rp_title != '') $output = '<'.$wp_rp_title_tag.' class="related_post_title">'.$wp_rp_title .''.$wp_rp_title_tag.'>'. $output;
}
return $output;
}
function wp_related_posts(){
$output = wp_get_related_posts() ;
echo $output;
}
function wp23_related_posts() {
wp_related_posts();
}
function wp_related_posts_auto($content){
$wp_rp = get_option("wp_rp");
if ((is_single() && $wp_rp["wp_rp_auto"])||(is_feed() && $wp_rp["wp_rp_rss"])) {
$output = wp_get_related_posts();
$content = $content . $output;
}
return $content;
}
add_filter('the_content', 'wp_related_posts_auto',99);
function wp_get_random_posts ($limitclause="") {
global $wpdb, $tableposts, $post;
$q = "SELECT ID, post_title, post_content,post_excerpt, post_date, comment_count FROM $tableposts WHERE post_status = 'publish' AND post_type = 'post' AND ID != $post->ID ORDER BY RAND() $limitclause";
return $wpdb->get_results($q);
}
function wp_random_posts ($number = 10){
$limitclause="LIMIT " . $number;
$random_posts = wp_get_random_posts ($limitclause);
foreach ($random_posts as $random_post ){
$output .= '';
$output .= ''.wptexturize($random_post->post_title).'';
}
$output = '';
echo $output;
}
function wp_get_most_commented_posts($limitclause="") {
global $wpdb;
$q = "SELECT ID, post_title, post_content, post_excerpt, post_date, COUNT($wpdb->comments.comment_post_ID) AS 'comment_count' FROM $wpdb->posts, $wpdb->comments WHERE comment_approved = '1' AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status = 'publish' GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC $limitclause";
return $wpdb->get_results($q);
}
function wp_most_commented_posts ($number = 10){
$limitclause="LIMIT " . $number;
$most_commented_posts = wp_get_most_commented_posts ($limitclause);
foreach ($most_commented_posts as $most_commented_post ){
$output .= '';
$output .= ''.wptexturize($most_commented_post->post_title).'';
}
$output = '';
echo $output;
}
function wp_get_most_popular_posts ($limitclause="") {
global $wpdb, $table_prefix;
$q = $sql = "SELECT p.ID, p.post_title, p.post_content,p.post_excerpt, p.post_date, p.comment_count FROM ". $table_prefix ."ak_popularity as akpc,".$table_prefix ."posts as p WHERE p.ID = akpc.post_id ORDER BY akpc.total DESC $limitclause";;
return $wpdb->get_results($q);
}
function wp_most_popular_posts ($number = 10){
$limitclause="LIMIT " . $number;
$most_popular_posts = wp_get_most_popular_posts ($limitclause);
foreach ($most_popular_posts as $most_popular_post ){
$output .= '';
$output .= ''.wptexturize($most_popular_post->post_title).'';
}
$output = '';
echo $output;
}
add_action('plugins_loaded', 'widget_sidebar_wp_related_posts');
function widget_sidebar_wp_related_posts() {
function widget_wp_related_posts($args) {
extract($args);
if(!is_single()) return;
echo $before_widget;
//echo $before_title . $wp_rp["wp_rp_title"] . $after_title;
$output = wp_get_related_posts($before_title,$after_title);
echo $output;
echo $after_widget;
}
register_sidebar_widget('Related Posts', 'widget_wp_related_posts');
}
add_action('admin_menu', 'wp_add_related_posts_options_page');
function wp_add_related_posts_options_page() {
if (function_exists('add_options_page')) {
add_options_page( __('Related Posts','wp_related_posts'), __('Related Posts','wp_related_posts'), 8, basename(__FILE__), 'wp_related_posts_options_subpanel');
}
}
function wp_related_posts_options_subpanel() {
if($_POST["wp_rp_Submit"]){
$message = __("WordPress Related Posts Setting Updated",'wp_related_posts');
$wp_rp_saved = get_option("wp_rp");
$wp_rp = array (
"wp_rp_title" => trim($_POST['wp_rp_title_option']),
"wp_rp_title_tag" => trim($_POST['wp_rp_title_tag_option']),
"wp_no_rp" => trim($_POST['wp_no_rp_option']),
"wp_no_rp_text" => trim($_POST['wp_no_rp_text_option']),
"wp_rp_except" => trim($_POST['wp_rp_except_option']),
"wp_rp_except_number" => trim($_POST['wp_rp_except_number_option']),
"wp_rp_limit" => trim($_POST['wp_rp_limit_option']),
'wp_rp_exclude' => trim($_POST['wp_rp_exclude_option']),
'wp_rp_auto' => trim($_POST['wp_rp_auto_option']),
'wp_rp_rss' => trim($_POST['wp_rp_rss_option']),
'wp_rp_comments' => trim($_POST['wp_rp_comments_option']),
'wp_rp_date' => trim($_POST['wp_rp_date_option']),
'wp_rp_thumbnail' => trim($_POST['wp_rp_thumbnail_option']),
'wp_rp_thumbnail_text' => trim($_POST['wp_rp_thumbnail_text_option']),
'wp_rp_thumbnail_post_meta' => trim($_POST['wp_rp_thumbnail_post_meta_option'])
);
if ($wp_rp_saved != $wp_rp)
if(!update_option("wp_rp",$wp_rp))
$message = "Update Failed";
echo '';
}
$wp_rp = get_option("wp_rp");
?>
WordPress Related Posts Plugin can generate a related posts list via WordPress tags, and add the related posts to feed.",'wp_related_posts');?>
denishua.