用代码让wordpress标签云,变成漂亮的标签云
点击数: 2004
文章目录
我这边提供二种样式给看家使用,
第一种样式
不用外挂,用代码实现漂亮wordpress标签云,开启主题的functions.php
贴入以下代码
- function colorCloud($text) {
- $text = preg_replace_callback('||i', 'colorCloudCallback', $text);
- return $text;
- }
- function colorCloudCallback($matches) {
- $text = $matches[1];
- $colors = array('F99','C9C','F96','6CC','6C9','37A7FF','B0D686','E6CC6E');
- $color=$colors[dechex(rand(0,7))];
- $pattern = '/style=(\'|\")(.*)(\'|\")/i';
- $text = preg_replace($pattern, "style=\"display: inline-block; *display: inline; *zoom: 1; color: #fff; padding: 1px 5px; margin: 0 5px 5px 0; background-color: #{$color}; border-radius: 3px; -webkit-transition: background-color .4s linear; -moz-transition: background-color .4s linear; transition: background-color .4s linear;\"", $text);
- $pattern = '/style=(\'|\")(.*)(\'|\")/i';
- return "";
- }
- add_filter('wp_tag_cloud', 'colorCloud', 1);
第二种样式
实现帅气wordpress的标签云做法
用代码实现帅气wordpress的标签云,开启主题的functions.php
贴入以下代码
- function colorCloud($text) { // 实现彩色标签云
- $text = preg_replace_callback('||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 "";
- }
- add_filter('wp_tag_cloud', 'colorCloud', 1);
注:若想在任意地方加入标签云,可以使用标签云的代码
如下
- 8&largest=22′); ?>