Often see other people's blog inside, or the site has such a random color, but the font size and the frequency of the label is related to the label cloud, so you want to write one. As for the color of the random display, it is very simple, this is not listed in the code.
Because you are learning thinkphp, data lookup is the use of TP data lookup statements.
1 Public functionRender$data ){2 //Find all the labels in the middle table of the post-tag many-to-many relationship3 $tags= M (' blog_tags ')Select ();4 $a=Array();5 //Remove duplicate labels, save all non-repeating labels in array a6 for($i= 0;$i<Count($tags);$i++) {7 if( !In_array($tags[$i[' Tid '],$a ) ){8 $a[$i] =$tags[$i[' Tid '];9 }Ten } One //Find all the post IDs under these tags and save them in the array bid A foreach($a as $v) { - $bid[$v] = M (' blog_tags ')->where (Array(' tid ' =$v))->field (' bid ')Select (); - } the foreach($bid as $v) { - $blog _id[] =$v; - } - //p ($a); + //P ($blog _id);d ie; - $b=$a;//Array B is used to hold the original array A, and the number of occurrences of the array a statistic label + foreach($a as $k=$v) { A $a[$k] =Array(); at for($j= 0;$j<Count($tags);$j++ ){ - if($v==$tags[$j[' Tid '] ) - $a[$k][0] + = 1; - } - } - $i= 0; in //combine tag ID, count count, tag name, post ID, into an array of C - foreach($b as $k=$v ){ to $name= M (' tags ')->where (Array(' id ' = =$v))->getfield (' name '); + $c[$i] =Array(' id ' = =$v, ' num ' =$a[$k][0], ' name ' = =$name, ' bid ' =$blog _id[$i] ); - $i++; the } * //p ($c);d ie; $ Panax Notoginseng $data[' tags '] =$c; - return $this->renderfile ("',$data); the}
In thinkphp, write the tag frequency statistic algorithm for many-to-many relationships in post tags