evolve_similar_posts

The evolve evolve similar posts function.

Description

evolve_similar_posts(); 

Usage

  1. if ( !function_exists( 'evolve_similar_posts' ) ) { 
  2. require_once '/library/functions/basic-functions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = evolve_similar_posts(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/library/functions/basic-functions.php  
  1. function evolve_similar_posts() { 
  2.  
  3. $post = ''; 
  4. $orig_post = $post; 
  5. global $post; 
  6. $evolve_similar_posts = evolve_get_option('evl_similar_posts', 'disable'); 
  7.  
  8. if ($evolve_similar_posts == "category") { 
  9. $matchby = get_the_category($post->ID); 
  10. $matchin = 'category'; 
  11. } else { 
  12. $matchby = wp_get_post_tags($post->ID); 
  13. $matchin = 'tag'; 
  14.  
  15. if ($matchby) { 
  16. $matchby_ids = array(); 
  17. foreach ($matchby as $individual_matchby) { 
  18. $matchby_ids[] = $individual_matchby->term_id; 
  19.  
  20. $args = array( 
  21. $matchin . '__in' => $matchby_ids,  
  22. 'post__not_in' => array($post->ID),  
  23. 'showposts' => 5, // Number of related posts that will be shown. 
  24. 'ignore_sticky_posts' => 1 
  25. ); 
  26.  
  27. $my_query = newwp_query$args); 
  28. if ($my_query->have_posts()) { 
  29. echo '<div class="similar-posts"><h5>' . __('Similar posts', 'evolve') . '</h5><ul>'; 
  30. while ($my_query->have_posts()) { 
  31. $my_query->the_post(); 
  32. ?> 
  33. <li> 
  34. <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php _e('Permanent Link to', 'evolve'); ?> <?php the_title(); ?>"> 
  35. <?php 
  36. if (get_the_title()) { 
  37. $title = the_title('', '', false); 
  38. $evolve_posts_excerpt_title_length = intval(evolve_get_option('evl_posts_excerpt_title_length', '40')); 
  39. echo evolve_truncate($title, $evolve_posts_excerpt_title_length, '...'); 
  40. } else { 
  41. echo __("Untitled", "evolve"); 
  42. ?> 
  43. </a> 
  44. <?php if (get_the_content()) { ?> — 
  45. <small><?php echo evolve_excerpt_max_charlength(60); ?></small> <?php } ?> 
  46. </li> 
  47. <?php 
  48. echo '</ul></div>'; 
  49. $post = $orig_post; 
  50. wp_reset_query();