# dedecms如何修改标签tag字体大小及随机颜色

*Published:* 2023-10-25
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2023年10月25日，已超过 180天没有更新



打开/include/common.func.php文件，在?&gt;之前加上下面的函数：

```
/*** dedecms标签<a class="tag_link" href="https://www.xarjtc.com/tag/tag" target="_blank" title="查看tag此标签更多文章"><abbr title="">tag</abbr></a>字体大小及颜色随机***/

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));
}
此函数的作用是输出随机的样式，包括font-size和color。
如果你想指定只显示几个字体大小，而不是完全随机，请将上面的函数代码修改为：
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));
}
```

在模板中调用代码如下：

```
{dede:tag row='50' getall='1' sort='hot'}
<a style="[field: total runphp=yes]@me=getTagStyle(); [/field: total];" title="[field:tag /]([field:total /])" href="[field:link/]">[field:tag /]</a>
{/dede:tag}
```