龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

Tinkphp彩色标签Tags的实现方法

时间:2014-07-22 14:50来源: 作者: 点击:
分享到:
彩色标签Tags br / 演示效果: a href=http://www.w3note.com rel=nofollowwww.w3note.com/a
彩色标签Tags
演示效果: www.w3note.com
我们浏览网页时经常看到眩目的彩色标签,而且每刷新一下浏览器,都会更新为不同的颜,是不是很“惊艳”?现在来看一下它在Thinkphp上的现实方法。

项目函数库的位置:项目\Common\common.php
项目函数库加入以下处理函数


1 function rcolor() {   

2 $rand = rand(0,255);//随机获取0--255的数字   

3 return sprintf("%02X","$rand");//输出十六进制的两个大写字母   

4 }   

5 function rand_color(){   

6     return '#'.rcolor().rcolor().rcolor();//六个字母   

7 } 
在控制器加入获取标签列表的方法

1 //标签控制器查询标签表以获取标签列表   

2     function Tags($Module) {   

3         $Tag = M('Tag');   

4         $map['module']= $Module;   

5         $Tagslist = $Tag->where($map)->field('id,name,count')->order('count desc')->limit('0,25')->select();   

6         $this->assign('tags', $Tagslist);   

7         $this->display();   

8      

9 } 
把标签列表输出在模板上


1 <volist id="vo" name="tags" >   

2  <li><a href="{:U('/web','tag='.$vo['name']|urlencode)}"><span style="font-size:{color:{$vo.id|rand_color}">&nbsp;&nbsp;{$vo.name}[{$vo.count}]</span></a></li>   

3   </volist> 
说明:{$vo.id|rand_color}为调用项目函数库的“ rand_color()”方法。



精彩图集

赞助商链接