Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/10/2011, 09:31
javierm5
 
Fecha de Ingreso: abril-2011
Mensajes: 72
Antigüedad: 13 años
Puntos: 4
Mostrar post_types mismo tag

Hola, esta vez estoy haciendo que debajo de cada artículo salga un apartado que ponga "Juegos relacionados" (otro post type, que tenga por lo menos un tag que coincida con la noticia). Sin saber PHP, iba haciendo lo que podía y al final sólo pasaron dos cosas que no pude solucionar:

1. Si no encontraba juegos mismo tag, no conseguí que mostrara un mensaje "No hay juegos relacionados".

2. Si los encontraba, todo el código que hay debajo de ese apartado desaparecía, los comentarios, etc.

He descubierto que sólo muestra los que tienen un único tag.

Podéis ver 2 ejemplos aquí, este no se muestra, y aquí sí.


Este es el código que puse:


<div class="postmeta-terciary">
&nbsp;
<h3>Juegos relacionados con la noticia:</h3>

<?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) {
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post_type' => juegos,
'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(); ?>

<?php
$juego = get_post_meta($post->ID, "Carátula del juego", true);
$altura = get_post_meta($post->ID, "Tipo de carátula", true);
$extracto = get_post_meta($post->ID, "Descripción", true);
?>

<div class="juego-item"><div class="thumbd"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"><img src="<?php echo($juego) ?>" align="left" class="<?php echo($altura) ?>" title="<?php the_title(); ?>" alt="<?php the_title(); ?>"></a></div>

<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="entry-content">
<?php echo($extracto); ?>
</div>
</div>
<?php
endwhile;
}
}

?>

</div>

Última edición por javierm5; 22/10/2011 a las 09:37