Guest User

related-posts.php

a guest
Sep 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 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.  
  10. $rp = avia_get_option('single_post_related_entries');
  11.  
  12.  
  13.  
  14.  
  15. if(!isset($avia_config['related_posts_config']))
  16. {
  17. $avia_config['related_posts_config'] = array(
  18.  
  19. 'columns' => 8,
  20. 'post_class' => "av_one_eighth no_margin ",
  21. 'image_size' => 'square',
  22. 'tooltip' => true,
  23. 'title_short'=> false
  24.  
  25. );
  26.  
  27. if($rp == "av-related-style-full")
  28. {
  29. $avia_config['related_posts_config'] = array(
  30.  
  31. 'columns' => 6,
  32. 'post_class' => "av_one_half no_margin ",
  33. 'image_size' => 'square',
  34. 'tooltip' => false,
  35. 'title_short'=> true
  36. );
  37. }
  38. }
  39.  
  40. if($rp == "disabled") return;
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. extract($avia_config['related_posts_config']);
  49.  
  50.  
  51. $is_portfolio = false; //avia_is_portfolio_single();
  52. $related_posts = false;
  53. $this_id = $post->ID;
  54. $slidecount = 0;
  55. $postcount = ($columns * 1);
  56. $format = "";
  57. $fake_image = "";
  58. $tags = wp_get_post_tags($this_id);
  59. $cat_ids = array();
  60. $categories = get_the_category($this_id);
  61.  
  62. if (!empty($categories))
  63. {
  64. $tag_ids = array();
  65. foreach ($tags as $tag ) {
  66.  
  67. if($tag->slug != "portrait" && $tag->slug != "landscape")
  68. {
  69. $tag_ids[] = (int)$tag->term_id;
  70. }
  71. }
  72.  
  73. if(!empty($categories))
  74. {
  75.  
  76. foreach($categories as $category)
  77. {
  78. $cat_ids[] = $category->term_id;
  79. }
  80.  
  81.  
  82. $my_query = get_posts(
  83. array(
  84. 'category__in' => $cat_ids,
  85. 'post_type' => get_post_type($this_id),
  86. 'showposts'=>$postcount, 'ignore_sticky_posts'=>1,
  87. 'orderby'=>'rand',
  88. 'post__not_in' => array($this_id))
  89. );
  90.  
  91. if (!empty($my_query))
  92. {
  93. $extra = 'alpha';
  94. $count = 1;
  95. $output = "";
  96.  
  97. //create seperator
  98.  
  99. $output .= "<div class ='related_posts {$rp}'>";
  100.  
  101.  
  102. $output .= "<h5 class='related_title'>".__('You might also like', 'avia_framework')."</h5>";
  103. $output .= "<div class='related_entries_container '>";
  104.  
  105. foreach ($my_query as $related_post)
  106. {
  107. $related_posts = true;
  108. $slidecount ++;
  109. $format = "";
  110. if($is_portfolio) $format = "portfolio";
  111. if(!$format) $format = get_post_format($related_post->ID);
  112. if(!$format) $format = 'standard';
  113. if(!empty($title_short)) $related_post->post_title = wp_trim_words($related_post->post_title, 17);
  114.  
  115.  
  116.  
  117. $post_thumbnail_id = get_post_thumbnail_id($related_post->ID);
  118. $post_thumb = get_the_post_thumbnail($related_post->ID, $image_size, array('title' => esc_attr(get_the_title($post_thumbnail_id))));
  119. $image = $post_thumb ? $post_thumb : "<span class='related_posts_default_image'>{image}</span>";
  120. $fake_image = $post_thumb ? $post_thumb : $fake_image;
  121. $extra_class= $post_thumb ? "" : "related-format-visible";
  122. $parity = $slidecount % 2 ? 'Odd' : 'Even';
  123. $insert_tooltip = $tooltip == true ? "data-avia-related-tooltip=\"". esc_attr($related_post->post_title)."\"" : "";
  124.  
  125. $output .= "<div class='$post_class $extra relThumb relThumb{$count} relThumb{$parity} post-format-{$format} related_column'>\n";
  126. $output .= " <a href='".get_permalink($related_post->ID)."' class='relThumWrap noLightbox' title='".esc_attr($related_post->post_title)."'>\n";
  127. $output .= " <span class='related_image_wrap' {$insert_tooltip}>";
  128. $output .= $image;
  129. $output .= " <span class='related-format-icon {$extra_class}'><span class='related-format-icon-inner' ".av_icon_string($format)."></span></span>";
  130. $output .= " </span>";
  131. $output .= "<strong class='av-related-title'>".$related_post->post_title."</strong>";
  132. $output .= apply_filters('avf_related_post_loop', "", $related_post);
  133. $output .= " </a>";
  134. $output .= "</div>";
  135.  
  136. $count++;
  137. $extra = "";
  138.  
  139. if($count == count($my_query)) $extra = 'omega';
  140.  
  141. }
  142.  
  143.  
  144. $output .= "</div></div>";
  145. $output = str_replace("{image}",$fake_image,$output);
  146.  
  147. if($related_posts) echo $output;
  148.  
  149. }
  150.  
  151. wp_reset_query();
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment