Guest User

Untitled

a guest
Jan 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. if (!function_exists('thumbs_rating_top_func')):
  2. function thumbs_rating_top_func($atts)
  3. {
  4. $return = '';
  5.  
  6. // Parameters accepted
  7.  
  8. extract(shortcode_atts(array(
  9. 'exclude_posts' => '',
  10. 'type' => 'positive',
  11. 'posts_per_page' => 5,
  12. 'category' => '',
  13. 'show_votes' => 'yes',
  14. 'post_type' => 'any',
  15. 'show_both' => 'no',
  16. 'order' => 'DESC',
  17. 'orderby' => 'meta_value_num'
  18. ) , $atts));
  19.  
  20. // Check wich meta_key the user wants
  21.  
  22. if ($type == 'positive')
  23. {
  24. $meta_key = '_thumbs_rating_up';
  25. $other_meta_key = '_thumbs_rating_down';
  26. $sign = "+";
  27. $other_sign = "-";
  28. }
  29. else
  30. {
  31. $meta_key = '_thumbs_rating_down';
  32. $other_meta_key = '_thumbs_rating_up';
  33. $sign = "-";
  34. $other_sign = "+";
  35. }
  36.  
  37. // Build up the args array
  38.  
  39. $args = array(
  40. 'post__not_in' => explode(",", $exclude_posts) ,
  41. 'post_type' => $post_type,
  42. 'post_status' => 'publish',
  43. 'cat' => $category,
  44. 'pagination' => false,
  45. 'posts_per_page' => $posts_per_page,
  46. 'cache_results' => true,
  47. 'meta_key' => $meta_key,
  48. 'order' => $order,
  49. 'orderby' => $orderby,
  50. 'ignore_sticky_posts' => true
  51. );
  52.  
  53. // Get the posts
  54.  
  55. $thumbs_ratings_top_query = new WP_Query($args);
  56.  
  57. // Build the post list
  58.  
  59. if ($thumbs_ratings_top_query->have_posts()):
  60. $return.= '';
  61. while ($thumbs_ratings_top_query->have_posts())
  62. {
  63. $thumbs_ratings_top_query->the_post();
  64. $return.= '<h2 class="lista-item-h2 lista-item-h2-grade flex">
  65.  
  66. <div class="listapop">
  67. <strong class="lista-ranking "><span class="figlista"></span></strong> </div>
  68.  
  69. <figure class="lista-item-foto">';
  70. $return.= '<div class="videoPlayer">
  71. ' . get_the_post_thumbnail($post_id, array(
  72. 'class' => ' videoPlayer__image lista-item-imagem'
  73. )) . '
  74. </div>
  75. </figure>
  76.  
  77.  
  78. ';
  79. $return.= '
  80. <div class="votar-lista">
  81.  
  82. ' . thumbs_rating_getlink() . '
  83.  
  84. </div>
  85.  
  86. ';
  87. $return.= '
  88.  
  89. <a class="titulo-da-lista modal-link" href="' . get_permalink() . '"> <div class="listItem__data"> <div class="trimtitulo"> ' . wp_trim_words(get_the_title() , 11, null) . ' </div> <span class="listItem__props">
  90. <span class="lista-item-blerg grey default"></span>';
  91. $return.= '<span class="wikipedia-lista block grey"> ' . mts_excerpt(32) . ' </span></span></div></a>
  92. </h2>';
  93. if ($show_votes == "yes")
  94. {
  95.  
  96. // Get the votes
  97.  
  98. $meta_values = get_post_meta(get_the_ID() , $meta_key);
  99.  
  100. // Add the votes to the HTML
  101.  
  102. $return.= ' (' . $sign;
  103. if (sizeof($meta_values) > 0)
  104. {
  105. $return.= $meta_values[0];
  106. }
  107. else
  108. {
  109. $return.= "0";
  110. }
  111.  
  112. // Show the other votes if needed
  113.  
  114. if ($show_both == 'yes')
  115. {
  116. $other_meta_values = get_post_meta(get_the_ID() , $other_meta_key);
  117. $return.= " " . $other_sign;
  118. if (sizeof($other_meta_values) > 0)
  119. {
  120. $return.= $other_meta_values[0];
  121. }
  122. else
  123. {
  124. $return.= "0";
  125. }
  126. }
  127.  
  128. $return.= ')';
  129. }
  130. }
  131.  
  132. // Reset the post data or the sky will fall
  133.  
  134. wp_reset_postdata();
  135. endif;
  136. return $return;
  137. }
  138.  
  139. add_shortcode('thumbs_rating_top', 'thumbs_rating_top_func');
  140. endif;
Add Comment
Please, Sign In to add comment