WordPress完成黑白标签云的办法

本文实例讲述了WordPress完成黑白标签云的办法。分享给大家供大家参考。详细剖析如下:

黑白标签云咱们在很多的网站都能够看到此类成果了,这里就来完成wordpress添加黑白标签云成果.

这种黑白标签云成果能够经过修正Simple Tags来显示。

1.在simple-tags.client.php中先找到如下代码:

function getColorByScale($scale_color, $min_color, $max_color)

2.正文掉(或许删除)getColorByScale这个function中的以下语句:

$scale_color = $scale_color / 100;  
$minr = hexdec(substr($min_color, 1, 2));
$ming = hexdec(substr($min_color, 3, 2));
$minb = hexdec(substr($min_color, 5, 2));
$maxr = hexdec(substr($max_color, 1, 2));
$maxg = hexdec(substr($max_color, 3, 2));
$maxb = hexdec(substr($max_color, 5, 2));
$r = dechex(intval((($maxr - $minr) * $scale_color) + $minr));
$g = dechex(intval((($maxg - $ming) * $scale_color) + $ming));
$b = dechex(intval((($maxb - $minb) * $scale_color) + $minb));

3.加上以下代码:
//Colorful Tag Cloud start  
$r = dechex(rand(0,255));
$g = dechex(rand(0,196));
$b = dechex(rand(0,255));

Colorful Tag Cloud end至于要显示多少个标签,怎样陈列,抢手标签和一般标签辨别为多少大小的字体,能够在后盾的Simple Tags的选项中设置. 
办法二,假如下面方法不能够咱们可参考如下方法。

后盾编辑 主题 的 functions.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);

能够看到,颜色是随机的,能够自行修正 $color = dechex(rand(0,16777215)); 这行来修正范畴,这样就很夸耀哈,而后在侧边栏 sidebar.php 里调用如下代码:
<?php wp_tag_cloud('smallest=8&largest=24&number=50'); ?>

即可,8 是最小的 tag 的字体大小(用的起码的 tag),24 是**的(用的最多的 tag),50 是 tag 的数目,能够自行修正.

心愿本文所述对大家的WordPress建站有所协助。

以上就是安达网络工作室关于《WordPress实现彩色标签云的方法》的一些看法。更多内容请查看本栏目更多内容!

本文相关话题: WordPress 彩色 标签云 方法
版权声明:本文为 安达网络工作室 转载文章,如有侵权请联系我们及时删除。
相关文章
在CentOS零碎上从零开端搭建WordPress博客的全流程记载

概述 最近买了台效劳器,预备搭建集体博客,来继续更新本人的博客, 环境 效劳器操作零碎:CentOS 7.0 ...

wordpress获取文章评论数过滤掉作者代码分享

复制代码代码如下://获取文章评论数,不蕴含作者本人function get_comments_number_filter_author() { g...

在WordPress的文章编辑器中设置默许内容的办法

很多时分咱们需求在给 WordPress 文章编辑器设置默许内容,比方把罕用的扫尾或许文章留意事项放出来,本文就...

WordPress中获取所应用的模板的页面ID的简略办法

什么是模板呢?默许状况 WordPress是应用主标题录下page.php来作为模板显示页面的,然而有时分咱们需求不同...

在WordPress中完成发送http申请的相干函数解析

在 PHP 中发送 Http 申请(GET / POST)有很多的办法,比方 file_get_contents() 函数、fopen() 函数或许 c...

解析WordPress中的post_class与get_post_class函数

post_class() post_class 是 WordPress 内置的一个用于显示文章 class 称号的函数,该函数通常会为每一篇文...

需求提交

客服服务

亿鸽在线客服系统