Home > CMS Tutorial > DEDECMS > body text

How DEDECMS implements color tag cloud

藏色散人
Release: 2019-11-16 10:53:36
Original
2089 people have browsed it

How DEDECMS implements color tag cloud

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));  
}
Copy after login

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));  
}
Copy after login

2. Use the following code to call the tag in the template.

{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}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!