Home  >  Article  >  CMS Tutorial  >  How to implement random color and font size in dedecms tag tag

How to implement random color and font size in dedecms tag tag

藏色散人
藏色散人Original
2019-12-27 09:23:431780browse

How to implement random color and font size in dedecms tag tag

dedecms tag How to achieve random color and font size?

The function we want to achieve is: the effect of the tag cloud, including tags with different colors and font sizes, etc. The colors and font sizes are randomly displayed, and the code can be changed to control its range. See It sounds pretty good. Let’s take a look at the implementation method. If you are interested, don’t miss it.

Recommended study: 梦Weavercms

Function description:

Realize the effect of tag cloud, including tags with different colors and font sizes. The colors and font sizes are randomly displayed, and the code can be changed to control their range.

Realize the effect of DeDeCms tag cloud, including tags with different colors and font sizes, etc. The colors and font sizes are randomly displayed, and the code can be changed to control its range.

Modification method:

1. Add the following function to /include/common.func.php.

The code is as follows:

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 a random style, 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:

The code is as follows:

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 in the template to call the tag.

The code is as follows:

{dede:tag row='45' getall='1' sort='hot'} 
<a href=&#39;[field:link/]&#39; 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 dede background, OK, let’s see the effect.

The above is the detailed content of How to implement random color and font size in dedecms tag tag. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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