Si eres de los que gustan de ir eliminando plugins para usar funciones ya disponibles en WordPress este es un estupendo hack que te puede ofrecer la funcionalidad de posts relacionados sin usar plugins como Related Posts u otros.
Solo tienes que añadir el siguiente código a la parte del ‘loop‘ en la que quieres que se muestren los posts relacionados (normalmente en single.php o index.php):
<?php
//para poner en el loop, muestra 5 titulos de post relacionados con la primera tag del post actual
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo 'Post relacionados';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Enlace permanente a <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
Inicio





Pingback: Bitacoras.com
Pingback: Posts relacionados sin plugin | Labrys
Pingback: Instalastes Wordpress huh?, ¿Qué sigue entonces? - Herramientas Online
Pingback: Artículos Post y Entradas Relacionadas sin Plugins WordPress | Nisfe.com
Pingback: 10 maneras de reducir el “bounce rate” en WordPress | Ayuda WordPress