Mostrar post relacionados en wordpress sin plugins - Bufa Webmaster

Bufa Webmaster

Recursos web en español

Mostrar post relacionados en wordpress sin plugins

7 feb 2010

Si no queremos usar un plugin para mostrar los post relacionados de un determinado post en wordpress podemos utilizar el siguiente script php. Este código se mostrará los post relacionados con las etiquetas o tags. Este script debe ser utilizado dentro del loop de wordpress.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$tags = wp_get_post_tags($post->ID);
if ($tags) {
  $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() ) {
	echo '<ul>';
    while ($my_query->have_posts()) : $my_query->the_post();
      echo '<li><a href="'.the_permalink().'" rel="bookmark">'.the_title().'</a></li>';
    endwhile;
	echo '</ul>';
  }
}
Compartir:
  • Google Bookmarks
  • Twitter
  • StumbleUpon
  • Digg
  • LinkedIn
  • del.icio.us
  • MisterWong
Tags:
Escribe un comentario

Spam Protection by WP-SpamFree

Bufa en Twiter

81 post | 52 comentarios | 118 tags | 5 suscriptores

Acerca de

bufa.es es una página web montada sobre wordpress que tiene como finalidad compartir la mayoría de recursos web (scripts, php, css, jquery, wordpress, plugins, posicionamiento web, etc...) utilizados por mi en el desarrollo web.

Entries (RSS) | Comments (RSS)

© 2010 Bufa Webmaster | valid XHTML and CSS | Powered by Wordpress and design bufa