彩色标签云
实现彩色标签云,颜色随即显示在主题function.php文件中添加下文:
<?php
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|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 "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
?>
function colorCloud($text) {
$text = preg_replace_callback('|<a (.+?)>|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 "<a $text>";
}
add_filter('wp_tag_cloud', 'colorCloud', 1);
?>
在主题中使用添加以下调用,标签中,最小字体大小为8,最大字字体大小为20,最多显示50个标签。
<?php wp_tag_cloud('smallest=8&largest=20&number=50'); ?>
| anyShare分享到: | |
| |
上一篇 « PSP便利商店携带版初级攻略 下一篇 » wp_get_archives()
发表评论 | Trackback 0 条评论.
