Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dokładka shortcode do skryptu w Wordpress
kedzier11
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 13.01.2014

Ostrzeżenie: (0%)
-----


Panowie pytanie dotyczy shortcode. Mam taki skrypt jak widać przez echo mogę wywoływać tę funkcję i zmienić parametry name, procenty itp. Chciał bym móc to zmieniać przy wykorzystaniu shortcode w wordpressie. Ale nie wiem jak. Czy ktoś pomoże? Dodam iż jestem początkującym programistom więc łopatologicznie proszę (IMG:style_emoticons/default/biggrin.gif)
  1. function pullRating($name,$show5 = true, $showPerc = false, $showVotes = true, $static = NULL){
  2.  
  3. // Check if they have already voted...
  4. $text = '';
  5.  
  6. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  7. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  8.  
  9.  
  10.  
  11. if($show5 || $showPerc || $showVotes){
  12.  
  13. $text .= '<div class="rated_text">';
  14.  
  15. }
  16.  
  17. if($show5){
  18. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  19. }
  20. if($showPerc){
  21. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  22. }
  23. if($showVotes){
  24. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  25. }
  26.  
  27. if($show5 || $showPerc || $showVotes){
  28.  
  29. $text .= '</div>';
  30.  
  31. }
  32.  
  33.  
  34. return $text.'
  35. <ul class="star-rating2" id="rater_'.$name.'">
  36. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  37. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  38. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  39. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  40. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  41. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  42. </ul>
  43. <div id="loading_'.$name.'"></div>';
  44.  
  45.  
  46. } else {
  47.  
  48. if($show5 || $showPerc || $showVotes){
  49.  
  50. $text .= '<div class="rated_text">';
  51.  
  52. }
  53. if($show5){
  54. $show5bool = 'true';
  55. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  56. } else {
  57. $show5bool = 'false';
  58. }
  59. if($showPerc){
  60. $showPercbool = 'true';
  61. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  62. } else {
  63. $showPercbool = 'false';
  64. }
  65. if($showVotes){
  66. $showVotesbool = 'true';
  67. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  68. } else {
  69. $showVotesbool = 'false';
  70. }
  71.  
  72. if($show5 || $showPerc || $showVotes){
  73.  
  74. $text .= '</div>';
  75.  
  76. }
  77.  
  78. return $text.'
  79. <ul class="star-rating" id="rater_'.$name.'">
  80. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  81. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  82. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  83. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  84. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  85. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  86. </ul>
  87. <div id="loading_'.$name.'"></div>';
  88.  
  89. }
  90. }add_shortcode('rater', 'pullRating');


Ten post edytował kedzier11 25.03.2014, 15:54:04
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
memory
post
Post #2





Grupa: Zarejestrowani
Postów: 616
Pomógł: 84
Dołączył: 29.11.2006
Skąd: bełchatów

Ostrzeżenie: (0%)
-----


  1. <?
  2.  
  3. add_shortcode('rater', 'pullRating');
  4.  
  5. function pullRating($attr){
  6.  
  7. $name = $attr['name'];
  8. $show5 = $attr['show5'];
  9. $showPerc=$attr['showPerc'];
  10. $showVotes=$attr['showVotes'];
  11. $static= $attr['static'];
  12.  
  13.  
  14. // Check if they have already voted...
  15. $text = '';
  16.  
  17. $sel = mysql_query("SELECT id FROM ratings WHERE IP = '".$_SERVER['REMOTE_ADDR']."' AND rating_id = '$name'");
  18. if(mysql_num_rows($sel) > 0 || $static == 'novote' || isset($_COOKIE['has_voted_'.$name])){
  19.  
  20.  
  21.  
  22. if($show5 || $showPerc || $showVotes){
  23.  
  24. $text .= '<div class="rated_text">';
  25.  
  26. }
  27.  
  28. if($show5){
  29. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  30. }
  31. if($showPerc){
  32. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  33. }
  34. if($showVotes){
  35. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  36. }
  37.  
  38. if($show5 || $showPerc || $showVotes){
  39.  
  40. $text .= '</div>';
  41.  
  42. }
  43.  
  44.  
  45. return $text.'
  46. <ul class="star-rating2" id="rater_'.$name.'">
  47. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  48. <li><a onclick="return false;" href="#" title="1 star out of 5" class="one-star" >1</a></li>
  49. <li><a onclick="return false;" href="#" title="2 stars out of 5" class="two-stars">2</a></li>
  50. <li><a onclick="return false;" href="#" title="3 stars out of 5" class="three-stars">3</a></li>
  51. <li><a onclick="return false;" href="#" title="4 stars out of 5" class="four-stars">4</a></li>
  52. <li><a onclick="return false;" href="#" title="5 stars out of 5" class="five-stars">5</a></li>
  53. </ul>
  54. <div id="loading_'.$name.'"></div>';
  55.  
  56.  
  57. } else {
  58.  
  59. if($show5 || $showPerc || $showVotes){
  60.  
  61. $text .= '<div class="rated_text">';
  62.  
  63. }
  64. if($show5){
  65. $show5bool = 'true';
  66. $text .= 'Rated <span id="outOfFive_'.$name.'" class="out5Class">'.outOfFive($name).'</span>/5';
  67. } else {
  68. $show5bool = 'false';
  69. }
  70. if($showPerc){
  71. $showPercbool = 'true';
  72. $text .= ' (<span id="percentage_'.$name.'" class="percentClass">'.getRating($name).'</span>)';
  73. } else {
  74. $showPercbool = 'false';
  75. }
  76. if($showVotes){
  77. $showVotesbool = 'true';
  78. $text .= ' (<span id="showvotes_'.$name.'" class="votesClass">'.getVotes($name).'</span>)';
  79. } else {
  80. $showVotesbool = 'false';
  81. }
  82.  
  83. if($show5 || $showPerc || $showVotes){
  84.  
  85. $text .= '</div>';
  86.  
  87. }
  88.  
  89. return $text.'
  90. <ul class="star-rating" id="rater_'.$name.'">
  91. <li class="current-rating" style="width:'.getRating($name).';" id="ul_'.$name.'"></li>
  92. <li><a onclick="rate(\'1\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=1" title="1 star out of 5" class="one-star" >1</a></li>
  93. <li><a onclick="rate(\'2\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=2" title="2 stars out of 5" class="two-stars">2</a></li>
  94. <li><a onclick="rate(\'3\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=3" title="3 stars out of 5" class="three-stars">3</a></li>
  95. <li><a onclick="rate(\'4\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=4" title="4 stars out of 5" class="four-stars">4</a></li>
  96. <li><a onclick="rate(\'5\',\''.$name.'\','.$show5bool.','.$showPercbool.','.$showVotesbool.'); return false;" href="includes/rating_process.php?id='.$name.'&rating=5" title="5 stars out of 5" class="five-stars">5</a></li>
  97. </ul>
  98. <div id="loading_'.$name.'"></div>';
  99.  
  100. }
  101. }
  102.  
  103. function getRating($name){
  104.  
  105.  
  106. $total = 0;
  107. $rows = 0;
  108.  
  109. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  110. if(mysql_num_rows($sel) > 0){
  111.  
  112. while($data = mysql_fetch_assoc($sel)){
  113.  
  114. $total = $total + $data['rating_num'];
  115. $rows++;
  116. }
  117.  
  118. $perc = ($total/$rows) * 20;
  119.  
  120. //$newPerc = round($perc/5)*5;
  121. //return $newPerc.'%';
  122.  
  123. $newPerc = round($perc,2);
  124. return $newPerc.'%';
  125.  
  126. } else {
  127.  
  128. return '0%';
  129.  
  130. }
  131. }
  132.  
  133. function outOfFive($name){
  134. $name = $_SERVER['REQUEST_URI'];
  135. $total = 0;
  136. $rows = 0;
  137.  
  138. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  139. if(mysql_num_rows($sel) > 0){
  140.  
  141. while($data = mysql_fetch_assoc($sel)){
  142.  
  143. $total = $total + $data['rating_num'];
  144. $rows++;
  145. }
  146.  
  147. $perc = ($total/$rows);
  148.  
  149. return round($perc,2);
  150. //return round(($perc*2), 0)/2; // 3.5
  151.  
  152. } else {
  153.  
  154. return '0';
  155.  
  156. }
  157.  
  158.  
  159. }
  160.  
  161. function getVotes($name){
  162. $name = $_SERVER['REQUEST_URI'];
  163. $sel = mysql_query("SELECT rating_num FROM ratings WHERE rating_id = '$name'");
  164. $rows = mysql_num_rows($sel);
  165. if($rows == 0){
  166. $votes = '0 Votes';
  167. }
  168. else if($rows == 1){
  169. $votes = '1 Vote';
  170. } else {
  171. $votes = $rows.' Votes';
  172. }
  173. return $votes;
  174.  
  175. }
  176.  
  177.  
  178.  
  179. // Added in version 1.5
  180. // Fixed sort in version 1.7
  181. function getTopRated($limit, $table, $namefield, $namefield){
  182. $name = $_SERVER['REQUEST_URI'];
  183. $result = '';
  184.  
  185. $sql = "SELECT COUNT(ratings.id) as rates,ratings.rating_id,".$table.".".$namefield." as thenamefield,ROUND(AVG(ratings.rating_num),2) as rating
  186. FROM ratings,".$table." WHERE ".$table.".".$namefield." = ratings.rating_id GROUP BY rating_id
  187. ORDER BY rates DESC,rating DESC LIMIT ".$limit."";
  188.  
  189. $sel = mysql_query($sql);
  190.  
  191. $result .= '<ul class="topRatedList">'."\n";
  192.  
  193. while($data = @mysql_fetch_assoc($sel)){
  194. $result .= '<li>'.$data['thenamefield'].' ('.$data['rating'].')</li>'."\n";
  195. }
  196.  
  197. $result .= '</ul>'."\n";
  198.  
  199. return $result;
  200.  
  201. }
  202. ?>
? co nie działa ?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.10.2025 - 00:21