Yo me encontré una vez esta función y me va muy bien:
Código PHP:
Ver original<?php
/* Post Relacionados ******/
function crossblock_get_related_posts() {
global $wpdb, $post,$table_prefix;
if ( $exclude != '' ) {
$q = "SELECT tt.term_id FROM ". $table_prefix ."term_taxonomy tt, " . $table_prefix . "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 . "'";
}
}
if ($limit) {
$limitclause = "LIMIT $limit";
} else {
$limitclause = "LIMIT 9";
}
$q = "SELECT p.ID, p.post_title, 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){
return;
}
foreach ($related_posts as $related_post ){
$output .= '<li><h3>';
/*
$show_date = true;
if ($show_date){
$dateformat = get_option('date_format');
$output .= '<span class="date">'.mysql2date($dateformat, $related_post->post_date) . "</span> - ";
}
*/
$output .= '<a href="'.get_permalink($related_post->ID).'" title="'.wptexturize($related_post->post_title).'">'.wptexturize($related_post->post_title).'';
if ($show_comments_count){
$output .= " (" . $related_post->comment_count . ")";
}
$output .= '</a></h3></li>';
}
$output = '<ul>'.$output.'</ul>';
$output = '<h3>Posts relacionados:</h3>'.$output;
// end $crossblock_postthumbnail_disable
return $output;
}
?>
Luego en donde quieras que se muestren los post relacionados, pues llamas la función y andando:
Código PHP:
Ver original<?php echo crossblock_get_related_posts(); ?>
Saludos
EDITO: Esa función la pones en tu archivo
functions.php