Advertisement
Guest User

Untitled

a guest
Oct 26th, 2013
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * These functions shows a number of posts related to the currently displayed post.
  5. * Relations are defined by tags: if post tags match, the post will be displayed as related
  6. */
  7. global $avia_config;
  8.  
  9. if(!isset($avia_config['related_posts_config']))
  10. {
  11. $avia_config['related_posts_config'] = array(
  12.  
  13. 'columns' => 8,
  14. 'post_class' => "av_one_eighth no_margin ",
  15. 'image_size' => 'square',
  16. 'tooltip' => true
  17.  
  18. );
  19. }
  20.  
  21.  
  22. extract($avia_config['related_posts_config']);
  23.  
  24.  
  25. $is_portfolio = false; //avia_is_portfolio_single();
  26. $related_posts = false;
  27. $this_id = $post->ID;
  28. $slidecount = 0;
  29. $postcount = ($columns * 1);
  30. $format = "";
  31. $fake_image = "";
  32.  
  33. $taxonomies = 'categories';
  34. $cats = wp_get_post_categories($this_id);
  35.  
  36. if(!empty($cats))
  37. {
  38. if(is_array($cats))
  39. {
  40. $my_query = get_posts(
  41. array(
  42. 'category__in' => $cats,
  43. 'post_type' => get_post_type($this_id),
  44. 'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
  45. 'orderby'=>'rand',
  46. 'post__not_in' => array($this_id))
  47. );
  48.  
  49.  
  50. if (!empty($my_query))
  51. {
  52. $extra = 'alpha';
  53. $count = 1;
  54. $output = "";
  55.  
  56. //create seperator
  57.  
  58. $output .= "<div class ='related_posts'>";
  59.  
  60.  
  61. $output .= "<h5 class='related_title'>".__('You might also like', 'avia_framework')."</h5>";
  62. $output .= "<div class='related_entries_container '>";
  63.  
  64. foreach ($my_query as $related_post)
  65. {
  66. $related_posts = true;
  67. $slidecount ++;
  68. $format = "";
  69. if($is_portfolio) $format = "portfolio";
  70. if(!$format) $format = get_post_format($related_post->ID);
  71. if(!$format) $format = 'standard';
  72.  
  73. $post_thumb = get_the_post_thumbnail( $related_post->ID, $image_size );
  74. $image = $post_thumb ? $post_thumb : "<span class='related_posts_default_image'>{image}</span>";
  75. $fake_image = $post_thumb ? $post_thumb : $fake_image;
  76. $extra_class= $post_thumb ? "" : "related-format-visible";
  77. $parity = $slidecount % 2 ? 'Odd' : 'Even';
  78. $insert_tooltip = $tooltip == true ? "data-avia-related-tooltip=\"". htmlspecialchars ( $related_post->post_title )."\"" : "";
  79.  
  80. $output .= "<div class='$post_class $extra relThumb relThumb{$count} relThumb{$parity} post-format-{$format} related_column'>\n";
  81. $output .= " <a href='".get_permalink($related_post->ID)."' class='relThumWrap noLightbox'>\n";
  82. $output .= " <span class='related_image_wrap' {$insert_tooltip}>";
  83. $output .= $image;
  84. $output .= " <span class='related-format-icon {$extra_class}'><span class='related-format-icon-inner' ".av_icon_string($format)."></span></span>";
  85. $output .= " </span>";
  86. $output .= apply_filters('avf_related_post_loop', "", $related_post);
  87. $output .= " </a>";
  88. $output .= "</div>";
  89.  
  90. $count++;
  91. $extra = "";
  92.  
  93. if($count == count($my_query)) $extra = 'omega';
  94.  
  95. }
  96.  
  97.  
  98. $output .= "</div></div>";
  99. $output = str_replace("{image}",$fake_image,$output);
  100.  
  101. if($related_posts) echo $output;
  102.  
  103. }
  104.  
  105. wp_reset_query();
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement