Artigos relacionados por categoria ao invés de TAGS
-
Pessoal, preciso muito de uma solução!
É o seguinte: O tema que estou usando para um projeto (Max Mag), mostra os artigos relacionados por TAGS, e isso não está fazendo com que ele mostre REALMENTE os artigos relacionados, porque para que todos os artigos apareçam no slider principal, preciso adicionar uma TAG em comum em todos eles. Por este motivo preciso que os artigos se relacionem por categorias e não por TAGS.
Podem me ajudar com isso?
Abaixo segue o código da função e da chamada dela dentro do single.php:
functions.php:
function getRelatedPosts( $count=4) { global $post; $orig_post = $post; $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=> $count, // Number of related posts that will be shown. 'ignore_sticky_posts'=>1 ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ) { ?> <div id="related-posts"> <h3><?php _e( 'Related Posts', 'mvp-text' ); ?></h3> <ul> <?php while( $my_query->have_posts() ) { $my_query->the_post(); ?> <li> <div class="related-image"> <?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) { ?> <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('medium-thumb'); ?></a> <?php } ?> <div class="related-text"> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </div><!--related-text--> </div><!--related-image--> <div class="related-small"> <a href="<?php the_permalink() ?>" class="main-headline"><?php the_title(); ?></a> </div><!--related-small--> </li> <?php } echo '</ul></div>'; } } $post = $orig_post; wp_reset_query(); }single.php:
<!-- Related Posts --> <strong><?php getRelatedPosts(); ?></strong> <?php comments_template(); ?> <?php endwhile; endif; ?> </div> <!--post-area--> </div><!--main --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Visualizando 1 resposta (de um total de 1)
Visualizando 1 resposta (de um total de 1)
O tópico ‘Artigos relacionados por categoria ao invés de TAGS’ está fechado para novas respostas.