Advertisement
Guest User

Untitled

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