<?php $randomPost = $wpdb->get_var(“SELECT guid FROM $wpdb->posts WHERE post_type = ‘post’ AND post_status = ‘publish’ ORDER BY rand() LIMIT 1″); $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id; $args=array( ‘category__in’ => $category_ids, ‘post__not_in’ => array($post->ID), ‘showpv9ts’=>3, ‘caller_get_posts’=>1 ); $my_query = new wp_query($args); if( $my_query->have_posts() ) { echo ‘<div id=”postsrelacionados”>Estudos Similares<ul>’; while ($my_query->have_posts()) { $my_query->the_post(); ?> <li><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li> <?php } echo ‘</ul>’; echo ‘</div>’; } } ?>
Excelente plugin para "Post Relacionados" ou "Related Post"
Depois de muita pesquisa consegui encontrar um plugin que atendia perfeitamente as minhas necessidades, o nome do plugin é "Related Post Thumbnails - Baixe a versão 1.3.1", se preferir acesse a "Página do Plugin Related Post Thumbnails". Esse plugin é ótimo, ele é leve, é facil de instalar e de configurar, relaciona os post corretamente e tem suporte a imagens. Dica: Você não encontra a opção de diminuir as imagens nas configurações do Plugin. Oo Plugin pega dinâmicamente as imagens que são reduzidas pelo próprio wordpress. Caso deseja diminur as imagens, configure a partir de CONFIGURAÇÕES > MIDIA > TAMANHO DA MINIATURA