彩色标签代码一段
//Color Tag Cloud function colorCloud($text) { $text = preg_replace_callback(‘||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 “”; } add_filter(‘wp_tag_cloud’, ‘colorCloud’, 1);
你的标签云就变彩色了,呵呵,是吧,当然我们也可以调整标签云的显示数量与大小,具体方法如下: 找到wp-includes/category-template.php文件,然后搜索wp_tag_cloud,这个就是标签云的调用函数了,查了一下参数表,得到wp_tag_cloud函数的参数如下:
smallest – Adjusts the size of the smallest tags in the cloud. Default is “8″. largest – Adjusts the size of the biggest tags in the cloud. Default is “22″. unit – Sets the unit type for font size (ie point or em). Default is “pt”. number – How many tags will display in the cloud. Default is “45″. format – “Flat” displays an inline cloud with each term separated by whitespace. “List” generates an unordered list. “Array” lets you define an array of tags. Default is “flat”. orderby – Sort the cloud by “name” or “count”. Default is “name”. order – Sort the cloud in ascending or descending order. Default is “ASC”.对照修改即可了。这其中主要参数的意思如下:unit=是字体大小的单位,使用我们熟悉的px最好;smallest=是指最小字体大小,自己修改;largest=是指最大字体大小,自己修改。还可以使用number=来设置标签的显示数量,orderby=来使得标签云按照标签的使用次数来排列等等。 比如修改’orderby’ => ‘name’的“name”为“count”则标签云按照标签的使用次数来排列,而不是以默认的按照名称来排列显示了。
代码很简单,但是要添加对位置,我们打开主题所在的文件夹,找到single.php这个文件,然后用记事本或者wordpress打开它,搜索一下这段代码,在它的后面添加上我上面给出的代码就行了,保存测试下,成功了吧,呵呵,这个方法简单易行,其余的都不好用。