今天研究了好久,终于发现点眉目。可以不用插件时间标签云的色彩化,而且可以自控字符大小。
简单地,可以把这段代码放入主题包 functions.php 文件中:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php wp_tag_cloud(‘smallest=8&largest=24&number=50’); ?>
<?php function colorCloud($text) { $text = preg_replace_callback(‘|<a (.+?)>|i’, ‘colorCloudCallback’, $text); return $text; } function colorCloudCallback($matches) { $text = $matches[1]; $color = dechex(rand(2197503,2197391)); $pattern = ‘/style=(\’|\”)(.*)(\’|\”)/i’; $text = preg_replace($pattern, “style=\”color:#{$color};$2;\””, $text); return “<a $text>”; } add_filter(‘wp_tag_cloud’, ‘colorCloud’, 1); ?> |