How DEDECMS implements a color tag cloud
DEDECMS color tag cloud-implements tag (TAG) randomization Color and size
Function description:
Realize the effect of tag cloud, including tags with different colors and font sizes, etc. The color and font size are randomly displayed and can be changed code to control its scope.
Recommended learning: dedecms tutorial
Modification method:
1. Add the following function to /include/common.func.php.
function getTagStyle() { $minFontSize=8; //最小字体大小,可根据需要自行更改 $maxFontSize=18; //最大字体大小,可根据需要自行更改 return 'font-size:'.($minFontSize+lcg_value()* (abs($maxFontSize-$minFontSize))).'px;color:#'.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255)); }
The function of this function is to output random styles, including font-size and color.
If you want to specify only a few font sizes to be displayed instead of completely random, please modify the above function code to:
function getTagStyle() { $sizearray = array('8','9','10','11','12','20'); //自定义字体大小,可根据需要自行修改 return 'font-size:'.$sizearray[rand(0,count($sizearray))]. 'pt;color:#'.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255)); }
2. Use the following code to call the tag in the template.
{dede:tag row='45' getall='1' sort='hot'} <a href='[field:link/]' title="[field:tag /]([field:total /])" style="[field:total runphp=yes]@me=getTagStyle();[/field:total]">[field:tag /]</a> {/dede:tag}
3. Generate the corresponding html in the background, OK, let’s see the effect.
The above is the detailed content of How DEDECMS implements color tag cloud. For more information, please follow other related articles on the PHP Chinese website!