Guest User

Untitled

a guest
Apr 15th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. function related_posts() {
  2.  
  3. global $post; //this is used by the loop down
  4.  
  5. if (!$this->is_single) {
  6. return;
  7. }
  8.  
  9.  
  10. if (td_util::get_option('tds_similar_articles') == 'hide') {
  11. return;
  12. }
  13.  
  14. if (td_util::get_option('tds_similar_articles_count') == '') {
  15. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  16. $tds_similar_articles_count = 3;
  17. } else {
  18. $tds_similar_articles_count = 2;
  19. }
  20.  
  21. } else {
  22. $tds_similar_articles_count = td_util::get_option('tds_similar_articles_count');
  23. }
  24.  
  25.  
  26.  
  27.  
  28. $buffy = '';
  29. $buffy .= '<div class="art-img-text-down similar-articles">';
  30.  
  31.  
  32. $args = array();
  33.  
  34. switch (td_util::get_option('tds_similar_articles_type')) {
  35.  
  36. //by tag
  37. case 'by_tag':
  38. $tags = wp_get_post_tags($this->post->ID);
  39. if ($tags) {
  40. $taglist = array();
  41. for ($i = 0; $i <= 4; $i++) {
  42. if (!empty($tags[$i])) {
  43. $taglist[] = $tags[$i]->term_id;
  44. } else {
  45. break;
  46. }
  47. }
  48. $args = array(
  49. 'tag__in' => $taglist,
  50. 'post__not_in' => array($this->post->ID),
  51. 'showposts' => $tds_similar_articles_count,
  52. 'ignore_sticky_posts' => 1
  53. );
  54. }
  55. break;
  56.  
  57.  
  58. //by title
  59. case 'by_auth':
  60. $args = array(
  61. 'author' => $this->post->post_author,
  62. 'post__not_in' => array($this->post->ID),
  63. 'showposts' => $tds_similar_articles_count,
  64. 'ignore_sticky_posts' => 1
  65. );
  66. break;
  67.  
  68.  
  69. //by category
  70. default:
  71. $args = array(
  72. 'category__in' => wp_get_post_categories($this->post->ID),
  73. 'post__not_in' => array($this->post->ID),
  74. 'showposts' => $tds_similar_articles_count,
  75. 'ignore_sticky_posts' => 1
  76. );
  77. break;
  78. }
  79.  
  80.  
  81.  
  82. if (!empty($args)) {
  83. //do the query
  84.  
  85. $post_categories = wp_get_post_categories($this->post->ID);
  86. $cats = array();
  87.  
  88. foreach($post_categories as $c){
  89. $cat = get_category( $c );
  90. $cats[] = array( 'name' => $cat->name, 'slug' => $cat->slug );
  91. }
  92.  
  93. $my_query = new WP_Query($args);
  94. if ($my_query->have_posts()) {
  95. $buffy .= '<h4 class="block-title"><span>' . __td('SIMILAR ARTICLES') . ' - ' . $cat->name . '</span></h4>';
  96.  
  97. $td_template_layout = new td_template_layout(''); //invalid sidebar position, it will default to 2 + 1
  98.  
  99. if (td_global::$cur_single_template_sidebar_pos == 'no_sidebar') {
  100. $td_template_layout->set_columns(3);
  101. } else {
  102. $td_template_layout->set_columns(2);
  103. }
  104.  
  105.  
  106. while ($my_query->have_posts()) : $my_query->the_post();
  107.  
  108. $buffy .= $td_template_layout->layout_open_element();
  109. $td_module_6 = new td_module_6($post);
  110. $buffy .= $td_module_6->render();
  111. $buffy .= $td_template_layout->layout_close_element();
  112.  
  113. $td_template_layout->layout_next();
  114. endwhile;
  115.  
  116. $buffy .= $td_template_layout->close_all_tags();
  117. }
  118. }
  119.  
  120.  
  121.  
  122.  
  123. $buffy .= '</div>';
  124.  
  125. wp_reset_query();
  126.  
  127. return $buffy;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment