Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //for use in the loop, list 5 post titles related to tags on current post
- function related_posts_by_tags(){
- global $post;
- $tags = wp_get_post_tags($post->ID);
- if ($tags) {
- echo '<h3 class="posts_relacionados">Se você gostou deste artigo, também vai se interessar por:</h3>';
- $t = array();
- foreach($tags as $tag){
- $t[] = $tag->term_id;
- }
- $args = array(
- 'tag__in' => $t,
- 'post__not_in' => array($post->ID),
- 'posts_per_page' => 5,
- 'caller_get_posts' => 1,
- 'post_type' => get_post_type()
- );
- $q = new WP_Query($args);
- /***** LISTA DAS IMAGENS DESTACADAS DOS POSTS RELACIONADOS *****/
- if( $q->have_posts() ) {
- echo '<ul class="galeria_posts_relacionados">';
- while ($q->have_posts()) : $q->the_post();
- echo '<li><a href="'. get_permalink() .'" rel="bookmark" title="'. the_title_attribute('echo=0'). '">'. get_the_post_thumbnail() .'</a></li>';
- endwhile;
- echo '</ul>';
- }
- /***** LISTA DAS IMAGENS DESTACADAS DOS POSTS RELACIONADOS *****/
- /***** LISTA DOS TÍTULOS DOS POSTS RELACIONADOS *****/
- if( $q->have_posts() ) {
- echo '<ul class="posts_relacionados">';
- while ($q->have_posts()) : $q->the_post();
- echo '<li><a href="'. get_permalink() .'" rel="bookmark" title="'. the_title_attribute('echo=0'). '">'. get_the_title() .'</a></li>';
- endwhile;
- echo '</ul>';
- }
- /***** LISTA DOS TÍTULOS DOS POSTS RELACIONADOS *****/
- wp_reset_query();
- }
- }
- /******************
- USAGE/MODO DE USAR:
- In page template, inside the loop, put this: related_posts_by_tags();
- ****************************************************/
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement