Artículos relacionados, mejora tu posicionamiento web
Conseguir un buen posicionamiento web para los artículos de la home de un blog o en los primeros nivel de este, no es “Complicado”. Por lo contrario cuando tenemos un blog con muchos post, los artículos más antiguos quedan enterados en las entrañas del blog, consiguiendo una menor visibilidad tanto para el usuario como para los buscadores.
Para solucionar este problema utilizaremos los artículos relacionados, de está manera estaremos ofreciendo al usuario contenido complementario al post actual y desenterraremos los post más antiguos para que consigan más visibilidad y mejorar su posicionamiento web.
En WordPress existen muchos plugins de artículos relacionados, pero en este caso vamos a utilizar un fragmento de código el cual nos va a mostrar post relacionados basados en los tags actuales del post.
El código debe ponerse en el Loop
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo ‘Related Posts’;
$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=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo ‘Related Posts’;
$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=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
Para modificar el numero de post relacionados a mostrar sólo hay que cambiar el numero de aquí “‘showposts’=>5,”, en vez de 5 poner por ejemplo 3
Fuente del código: http://www.wprecipes.com/how-to-show-related-posts-without-a-plugin