Guest User

Untitled

a guest
Jan 4th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.08 KB | None | 0 0
  1. <?php
  2. /**
  3. * Récupère les articles similaires
  4. *
  5. * @author   Michaël Ambass
  6. **/
  7.  
  8. // On garde en mémoire le post
  9. $recover = $post;
  10.  
  11. // Récupère les tags du post
  12. $tags = wp_get_post_tags($post->ID);
  13. $tagsName = array();
  14.  
  15. // S'il y a des tags on commence le match
  16. if($tags){
  17.    
  18.     for($i = 0; $i < count($tags); $i++){
  19.         $tagsName[$i] = $tags[$i]->term_id;
  20.     }
  21. }
  22.  
  23. // Règle les arguments
  24. $args = array(
  25.     'tag__in' => $tagsName,
  26.     'post__not_in' => array($post->ID),
  27.     'showposts' => 4,
  28.     'orderby' => rand
  29. );
  30.  
  31. // Recherche les articles
  32. $search = new WP_Query($args);
  33. if($search->have_posts()){
  34.     ?>
  35.     <div class="similar_box">
  36.         <div class="similar_content">
  37.             <h4># Soif de lecture ?</h4>
  38.  
  39.     <?php
  40.     while($search->have_posts()){
  41.         $search->the_post();
  42. ?>
  43.     <div class="similar_entry">
  44.         <div class="similar_thumb"><?php the_post_thumbnail('similar'); ?></div>
  45.         <div class="similar_title">
  46.             <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  47.             <div class="similar_date">Publié le <?php the_date('d M Y'); ?></div>
  48.         </div>
  49.     </div>
  50. <?php      
  51.        
  52.     }
  53.     ?>
Add Comment
Please, Sign In to add comment