WordPress的标签可以随意个性化,你可以设计成彩色的、加文字背景的、3D的等等,现在介绍一个免插件的彩色背景的实现方法。
添加彩色背景标签云
切换到主题主目录,把这段代码复制到functions.php文件,保存即可实现彩色背景标签云
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);
侧栏调用标签云
以下就是调用方法
<?php if ( !function_exists('dynamic_sidebar')
|| !dynamic_sidebar('Third_sidebar') ) : ?>
<h3>标签云</h3>
<p><?php wp_tag_cloud('smallest=8&largest=22'); ?></p>
<?php endif; ?>
还没有评论,发表第一个评论吧