term_taxonomy.' tt, ' . $wpdb->term_relationships.' tr WHERE tt.taxonomy = \'category\' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = '.$post->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 5"; } $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= ""; $output .= '
  • '.$wp_no_rp_text .'
  • '; } else{ if($wp_no_rp == "random"){ if(!$wp_no_rp_text) $wp_no_rp_text= "Random 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"; $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"; $related_posts = wp_get_most_popular_posts($limitclause); } $wp_rp_title = $wp_no_rp_text; } } foreach ($related_posts as $related_post ){ $output .= '
  • ' . '' . get_the_post_thumbnail( $related_post->ID, 'thumbnail','' ) . ''; $output .= ' '. wptexturize($related_post->post_title) . ''; $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 .''. $output; } return $output; } function wp_related_posts(){ $output = wp_get_related_posts() ; echo $output; } ?>