功能介绍

修改替换默认标签云背景颜色改为定义好的颜色,让标签云更加的好看!

功能展示

RiProV2美化-彩色标签云插图

配置教程

首先利用宝塔或则FTP打开/inc/options下的admin-options.php文件把下面代码放在20行左右

  1. array(
  2. ‘id’ => ‘is_tags_cloud’,
  3. ‘type’ => ‘switcher’,
  4. ‘title’ => ‘彩色标签云’,
  5. ‘label’ => ‘启用后标签云中的标签的颜色为随机颜色’,
  6. ‘default’ => false,
  7. ),

最后在主题根目录下打开functions.php将以下代码放在最后即可

  1. //+———————————————————————-
  2. //| 标签云彩色代码
  3. //+———————————————————————-
  4. if (_cao(‘is_tags_cloud’)) {
  5.  
  6. function colorCloud($text) {
  7. $text = preg_replace_callback(‘|<a (.+?)>|i’, ‘colorCloudCallback’, $text);
  8.  
  9. return $text;
  10. }
  11. function colorCloudCallback($matches) {
  12. $text = $matches[1];
  13. $colors = array(‘F99’,‘C9C’,‘F96’,‘6CC’,‘6C9’,’37A7FF’,‘B0D686’,‘E6CC6E’,‘FF00FF’,‘D9D919’,‘238E23’,‘F47920’,‘bed742’,‘6950a1’,’65c294′,‘7fb80e’,‘6a6da9’,‘9b95c9’);
  14. $color=$colors[dechex(rand(0,7))];
  15. $pattern = ‘/style=(\’|\”)(.*)(\’|\”)/i’;
  16. $text = preg_replace($pattern, “style=\”display: inline-block; *display: inline; *zoom: 1; color: #fff; padding: 1px 2px; margin: 0 2px 2px 0; background-color: #{$color}; border-radius: 2px; -webkit-transition: background-color .4s linear; -moz-transition: background-color .4s linear; transition: background-color .4s linear;\””, $text);
  17. $pattern = ‘/style=(\’|\”)(.*)(\’|\”)/i’;
  18. return “<a $text>”;
  19. }
  20. add_filter(‘wp_tag_cloud’, ‘colorCloud’, 1);
  21. }