本文实例讲述了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));//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);<?php wp_tag_cloud('smallest=8&largest=24&number=50'); ?>
即可,8 是最小的 tag 的字体大小(用的起码的 tag),24 是**的(用的最多的 tag),50 是 tag 的数目,能够自行修正.
心愿本文所述对大家的WordPress建站有所协助。
以上就是安达网络工作室关于《WordPress实现彩色标签云的方法》的一些看法。更多内容请查看本栏目更多内容!
概述 最近买了台效劳器,预备搭建集体博客,来继续更新本人的博客, 环境 效劳器操作零碎:CentOS 7.0 ...
复制代码代码如下://获取文章评论数,不蕴含作者本人function get_comments_number_filter_author() { g...
很多时分咱们需求在给 WordPress 文章编辑器设置默许内容,比方把罕用的扫尾或许文章留意事项放出来,本文就...
什么是模板呢?默许状况 WordPress是应用主标题录下page.php来作为模板显示页面的,然而有时分咱们需求不同...
在 PHP 中发送 Http 申请(GET / POST)有很多的办法,比方 file_get_contents() 函数、fopen() 函数或许 c...
post_class() post_class 是 WordPress 内置的一个用于显示文章 class 称号的函数,该函数通常会为每一篇文...