欢迎访问 舍力博客(www.shuyong.net)
<?php //widget:标签 function widget_tag($title){ global $CACHE; $tag_cache = $CACHE->readCache('tags'); shuffle($tag_cache); //添加这行代码实现标签随机排序 $num='20';指定标签个数 ?> <?php foreach($tag_cache as $key => $value):if($key < $num): $color = dechex(rand(3355443,13421772));?> <li class="tags"><a class="label" style="background:#<?php echo $color; ?>" href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇文章"><?php echo $value['tagname'],' +',$value['usenum']; ?></a></li> <?php endif; endforeach; }?>2、将标签排序按条件显示:
<?php //widget:标签 function widget_tag($title){ global $CACHE; $tag_cache = $CACHE->readCache('tags'); //start 开始排序 foreach ($tag_cache as $key => $row) { $usenum[$key] = $row['usenum']; } array_multisort($usenum, SORT_DESC, $tag_cache); //end 获取排序后的新数组 $tag_cache ?> ……省略外层的div+css <?php foreach($tag_cache as $value): if($value['usenum'] > '1'): //1可以更改为大于1的其他数字,控制文章相关数 $color = dechex(rand(3355443,13421772));?> <li class="tags"><a class="label" style="background:#<?php echo $color; ?>" href="<?php echo Url::tag($value['tagurl']); ?>" title="<?php echo $value['usenum']; ?> 篇文章"><?php echo $value['tagname'],' +',$value['usenum']; ?></a></li> <?php endif; endforeach; }?>
留言/评论:◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。