实现织梦dedecms多彩标签云的效果,包括标签有不同的颜色和字体大小等等,颜色和字体大小都为随机显示,可改变代码来控制其范围。
步骤一
在/include/common.func.php 中加入如下函数,此函数的作用是输出随机的样式,包括font-size和color。
1 2 3 4 5 6 | function getTagStyle() { $minFontSize =12; //最小字体大小,可根据需要自行更改 $maxFontSize =25; //最大字体大小,可根据需要自行更改 return 'font-size:' .( $minFontSize +lcg_value()*( abs ( $maxFontSize - $minFontSize ))).'px;color:#’. dechex (rand(0,255)). dechex (rand(0,196)). dechex (rand(0,255)); } |
步骤二
在模板页htm里调用标签时用如下类似的方式。
1 2 3 4 5 6 7 8 9 10 11 12 | <!-- /下面开始tag标签云 --> < div > < dl class = "tbox light" > < dt >< strong >Tags标签云</ strong ></ dt > < dd > {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} </ dd > </ dl > </ div > <!-- /tag标签云结束 --> |
附加说明
如果你想指定只显示几个字体大小,而不是完全随机,请将步骤一中的函数代码替换为:
1 2 3 4 5 | 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)); } |