Guest User

Untitled

a guest
Apr 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * related posts block, used on single post template to show the related posts by tag author etc.
  5. * @see td_module_single::related_posts
  6. */
  7. class td_block_related_posts extends td_block {
  8.  
  9.  
  10. function render($atts, $content = null) {
  11. parent::render($atts); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)
  12.  
  13. // this block need td_column_number to add rows if more posts are displayed on a post.
  14. /// the td_column_number is not standard here, it's 5 for full width / 3 for content + sidebar
  15. extract(shortcode_atts(
  16. array(
  17. 'td_column_number' => ''
  18. ), $atts));
  19.  
  20.  
  21. // we have no related posts to display
  22. if ($this->td_query->post_count == 0) {
  23. return;
  24. }
  25.  
  26.  
  27. $buffy = ''; //output buffer
  28.  
  29. //get the js for this block
  30. $buffy .= $this->get_block_js();
  31.  
  32. $buffy .= '<div class="' . $this->get_block_classes() . '" ' . $this->get_block_html_atts() . '>';
  33.  
  34. //get the filter for this block
  35. $buffy .= '<h4 class="td-related-title">';
  36. $buffy .= '<a id="' . td_global::td_generate_unique_id() . '" class="td-related-right td-cur-simple-item" data-td_filter_value="td_related_more_from_author" data-td_block_id="' . $this->block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
  37. $buffy .= '<a id="' . td_global::td_generate_unique_id() . '" class="td-related-left " data-td_filter_value="" data-td_block_id="' . $this->block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
  38.  
  39. $buffy .= '</h4>';
  40.  
  41. $buffy .= '<div id=' . $this->block_uid . ' class="td_block_inner">';
  42. $buffy .= $this->inner($this->td_query->posts, $td_column_number); //inner content of the block
  43. $buffy .= '</div>';
  44.  
  45. //get the ajax pagination for this block
  46. $buffy .= $this->get_block_pagination();
  47. $buffy .= '</div> <!-- ./block -->';
  48. return $buffy;
  49. }
  50.  
  51. function inner($posts, $td_column_number = '') {
  52.  
  53.  
  54. $td_block_layout = new td_block_layout();
  55. $td_block_layout->row_class = 'td-related-row';
  56. $td_block_layout->span4_class = 'td-related-span4';
  57.  
  58.  
  59. $buffy = '';
  60.  
  61.  
  62.  
  63.  
  64. $td_current_column = 1; //the current column
  65.  
  66. if (!empty($posts)) {
  67. foreach ($posts as $td_post_count => $post) {
  68.  
  69. $td_module_related_posts = new td_module_related_posts($post);
  70.  
  71.  
  72.  
  73. switch ($td_column_number) {
  74. case '3': //the layout when we are on content + sidebar
  75.  
  76. $buffy .= $td_block_layout->open_row();
  77. $buffy .= $td_block_layout->open4();
  78. $buffy .= $td_module_related_posts->render();
  79. $buffy .= $td_block_layout->close4();
  80.  
  81. if ($td_current_column == 3) {
  82. $buffy .= $td_block_layout->close_row();
  83. }
  84.  
  85. break;
  86.  
  87. case '5': //the layout when we are on
  88.  
  89.  
  90. $buffy .= $td_block_layout->open_row();
  91. $buffy .= $td_block_layout->open4();
  92. $buffy .= $td_module_related_posts->render();
  93. $buffy .= $td_block_layout->close4();
  94.  
  95. if ($td_current_column == 5) {
  96. $buffy .= $td_block_layout->close_row();
  97. }
  98.  
  99. break;
  100. }
  101.  
  102.  
  103. //current column
  104. if ($td_current_column == $td_column_number) {
  105. $td_current_column = 1;
  106. } else {
  107. $td_current_column++;
  108. }
  109. } //end for each
  110.  
  111.  
  112.  
  113. }
  114.  
  115. $buffy .= $td_block_layout->close_all_tags();
  116. return $buffy;
  117.  
  118. }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment