A piece of code to implement tag cloud in php

WBOY
Release: 2016-07-25 09:03:26
Original
837 people have browsed it
  1. /**
  2. * WNiaoBlog Tag Template ShowTag
  3. *
  4. * @package WNiaoBlog
  5. *
  6. * @subpackage Tag
  7. */
  8. //Connect the database
  9. //include('../include/config.php');
  10. /**
  11. * CountTag() - Statistics labels appear the number,and the data to be stored in the two array
  12. *
  13. * GetTag() - Access the Tag's Labels from the database
  14. */
  15. function CountTag($String){
  16. $TagString = $String;
  17. //echo $TagString."
  18. ";
  19. $Tags = explode(",",$TagString);
  20. $n = 1;
  21. $i = 0;
  22. $Continue = TRUE;
  23. //echo $Tags[1]."
  24. ";
  25. //in case no-label's article
  26. while($Tags[$n] OR $Tags[++$n] OR $Tags[++$n] ){
  27. $EachTag = $Tags[$n++];
  28. //echo $EachTag."
  29. ";
  30. $Continue = TRUE;
  31. for($i=0;$Continue;$ i++){
  32. if( $EachTagStr[$i][0] ) {
  33. if( $EachTagStr[$i][0] == $EachTag ){
  34. $EachTagStr[$i][1]++;
  35. $ Continue = FALSE;
  36. }
  37. else {
  38. if( $EachTagStr[$i+1][0] ) $Continue = TRUE;
  39. else {
  40. $EachTagStr[$i+1][0] = $EachTag;
  41. $ EachTagStr[$i+1][1] = 1;
  42. $Continue = FALSE;
  43. }
  44. }
  45. } else { //initialize the array $EachTagStr[][]
  46. $EachTagStr[$i][0] = $ EachTag;
  47. $EachTagStr[$i][1] = 1;
  48. $Continue = FALSE;
  49. }
  50. }
  51. }
  52. return $EachTagStr;
  53. }
  54. function ShowTag($Row,$ablink){
  55. $i = 0 ;
  56. while($Row[$i][0]){
  57. $EachTag = $Row[$i][0];
  58. $EachCount = $Row[$i][1];
  59. $Size = SetSize($ EachCount);
  60. echo " < a style='color:BLUE ; font-size:".$Size." ' onMouseOver=this.style.color='#900000' onMouseOut=this.style.color='BLUE' href='".$ablink."tag?tag=".$EachTag."' target='_self' > ".$EachTag."(".$EachCount.")"." ";
  61. $i++;
  62. }
  63. }
  64. function GetTag(){
  65. $QuerySet = mysql_query("select * from article");
  66. while($Row = mysql_fetch_array($QuerySet)){
  67. $Tag = $Row[ 'tag'];
  68. $TagString = $TagString.",".$Tag;
  69. }
  70. return $TagString;
  71. }
  72. function SetSize($Size){
  73. $Size += 10;
  74. if($Size > 30)
  75. $Size = 30;
  76. return $Size;
  77. }
  78. //Go
  79. echo "
  80. ";
  81. echo "电影云";
  82. $String = GetTag();
  83. $Row = CountTag($String);
  84. ShowTag($Row,$ablink);
  85. echo "
  86. ";
  87. ?>
copy code


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template