「WP标签云」自定义WordPress彩色标签云。

效果图:

img

操作步骤:

1)到主机后台的「主题根目录」新建一个名为「functions.php」的文件(如有的话直接粘贴代码);

//WordPress圆角彩色背景标签云
function colorCloud($text) {  
$text = preg_replace_callback('|<a (.+?)>|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 "<a $text>";  
}  
add_filter('wp_tag_cloud', 'colorCloud', 1);

2)点击「编辑」然后粘贴代码点击「提交」;

img

img

3)WP后台写文章是插入标签(建议一个文章一个标签);

img

4)编辑文章并发布即可;

© 版权声明
THE END
喜欢就支持一下吧
点赞3赞赏
分享
相关推荐
  • 暂无相关文章
  • 评论 抢沙发
    邹仲輝的头像-有趣、有料且高效邹仲輝

    昵称

    取消
    昵称