Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Récupère les articles similaires
- *
- * @author Michaël Ambass
- **/
- // On garde en mémoire le post
- $recover = $post;
- // Récupère les tags du post
- $tags = wp_get_post_tags($post->ID);
- $tagsName = array();
- // S'il y a des tags on commence le match
- if($tags){
- for($i = 0; $i < count($tags); $i++){
- $tagsName[$i] = $tags[$i]->term_id;
- }
- }
- // Règle les arguments
- $args = array(
- 'tag__in' => $tagsName,
- 'post__not_in' => array($post->ID),
- 'showposts' => 4,
- 'orderby' => rand
- );
- // Recherche les articles
- $search = new WP_Query($args);
- if($search->have_posts()){
- ?>
- <div class="similar_box">
- <div class="similar_content">
- <h4># Soif de lecture ?</h4>
- <?php
- while($search->have_posts()){
- $search->the_post();
- ?>
- <div class="similar_entry">
- <div class="similar_thumb"><?php the_post_thumbnail('similar'); ?></div>
- <div class="similar_title">
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- <div class="similar_date">Publié le <?php the_date('d M Y'); ?></div>
- </div>
- </div>
- <?php
- }
- ?>
Add Comment
Please, Sign In to add comment