This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( have_posts() ) : | |
while ( have_posts() ) : the_post(); | |
// contenido de la entrada E (template tags, html, etc) | |
?><h2> | |
<a href="<?php the_permalink(); ?>"><?php the_title();?></a> | |
</h2><?php | |
the_content(); | |
// cogemos las etiquetas de la entrada E actual | |
$tags = wp_get_post_terms( get_the_ID() ); | |
if ( $tags ) { | |
echo 'Entradas Relacionadas'; | |
$tagcount = count( $tags ); | |
for ( $i = 0; $i < $tagcount; $i++ ) { | |
// recogemos los IDs de las etiquetas | |
// de la entrada E | |
$tagIDs[$i] = $tags[$i]->term_id; | |
} | |
// parámetros para el loop anidado donde queremos | |
// 5 entradas que tengan las mismas etiquetas y | |
// no sean la entrada E | |
$args = array( | |
'tag__in' => $tagIDs, | |
'post__not_in' => array( $post->ID ), | |
'posts_per_page' => 5, | |
'ignore_sticky_posts' => 1 | |
); | |
$relatedPosts = new WP_Query( $args ); | |
if( $relatedPosts->have_posts() ) { | |
// Loop anidado de entradas relacionadas basándonos en etiquetas | |
while ( $relatedPosts->have_posts() ) : | |
$relatedPosts->the_post(); ?> | |
<p> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> | |
</p><?php | |
endwhile; | |
} | |
} | |
endwhile; | |
endif; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!–– primer loop --> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<!–– mostrar contenido aqui ––> | |
<?php endwhile; ?> | |
<!-- rebobinamos el loop --> | |
<?php rewind_posts(); ?> | |
<!-- segundo loop usando los mismos datos que el primero --> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<!–– mostrar contenido aqui ––> | |
<?php endwhile; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$entradas = new WP_Query( 'posts_per_page=10&orderby=rand' ); | |
// The Loop | |
while ( $entradas->have_posts() ) : | |
$entradas->the_post(); ?> | |
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><br /><?php | |
endwhile; | |
// Resetear Post Data | |
wp_reset_postdata(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment