Realize the effect of Zhimeng DedeCMS colorful label cloud, including labels with different colors and font sizes. The colors and font sizes are displayed randomly, and the code can be changed to control its range.

 Zhimeng DedeCMS Implementation of Colorful Label Cloud and Random Color and Font Size of Tags

1. Add the following function to/include/common. func.php to output random styles, including font size and color.

function getTagStyle()
{
$minFontSize=12; // The minimum font size can be changed as needed
$maxFontSize=25; // The maximum font size can be changed according to needs
return
'font-size:’. ($minFontSize+lcg_value()*(abs($maxFontSize-$minFontSize))).’ px; color:#’.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255));
}

2. The following similar method is used when calling tags in the template page htm.

<a href=’[field:link/]' title=”[field:tag /]” style=”[field:total runphp=yes]@me=getTagStyle(); [/field:total]“>[field:tag /]</a>

Additional instructions

If you want to specify that only a few font sizes are displayed instead of being completely random, please replace the function code in Step 1 with

$sizearray = array('8′,’9′,’10′,’11′,’12′,’20′); // Custom font size

It can be modified as needed

return 'font-size:’.$ sizearray[rand(0,count($sizearray))].’ pt; color:#’.dechex(rand(0,255)).dechex(rand(0,196)).dechex(rand(0,255));

Post reply

Can't comment until