实现WordPress彩色标签云的震撼效果
实现彩色功能,在主题的function.php文件中加入以下函数
-
- function colorCloud($text) {
- $text = preg_replace_callback('|<a (.+?)>;|i','colorCloudCallback', $text);
- return $text;
- }
- function colorCloudCallback($matches) {
- $text = $matches[1];
- $color = dechex(rand(0,16777215));
- $pattern = '/style=(\'|\”)(.*)(\'|\”)/i';
- $text = preg_replace($pattern, "style="color:#{$color};$2;"", $text);
- return "<a $text>;";
- }
- add_filter('wp_tag_cloud', 'colorCloud', 1);
复制代码
调用tag云
-
- <?php wp_tag_cloud('smallest=12&largest=18&unit=px&number=0&orderby=count&order=DESC');?>;
复制代码
smallest表示标签的最小字号
largest表示最大字号
unit=px表示字体使用像素单位
number=0表示显示所有标签,如果为40,表示显示40个
orderby=count表示按照标签所关联的文章数来排列
order=DESC表示降序排序(ASC表示升序排序,DESC表示降序排序)
指定在页脚显示,例如老牛自己的
-
- <div id="footerTagCloud">;
- <?php if ( function_exists('wp_tag_cloud') ) : ?>;
- <strong>热门标签</strong>;
- <?php wp_tag_cloud('smallest=8&largest=22'); ?>;
- <?php endif; ?>;
- </div>;
复制代码
其中的DIV CSS样式请自行匹配各自的主题进行修改
|