Introduction of Color Tag Cloud method in WordPress

Source: Internet
Author: User

This color tag cloud effect can be displayed by modifying simple tags.

1. Find the function of Getcolorbyscale first in simple-tags.client.php:

The code is as follows Copy Code

function Getcolorbyscale ($scale _color, $min _color, $max _color)

2. Comment out (or delete) Getcolorbyscale The following statement in this function:

  code is as follows copy code

$scale _color = $scale _color/100;
$minr = Hexdec (substr ($min _color, 1, 2)); br> $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. Add the following code:

//colorful Tag Cloud start

$r = Dechex (rand (0,255));
$g = Dechex (rand (0,196));
$b = Dechex (rand (0,255));

Colorful tag Cloud end as to how many labels to display, how to arrange, popular tags and ordinary labels are the size of the font, can be in the background of simple tags in the options set.


Method Two, if the above method is not possible we can refer to the following method.


Background edit the functions.php of the subject, enter the following code

The code is as follows Copy Code

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);

As you can see, the color is random and can be modified $color = Dechex (rand (0,16777215)); This line to modify the scope, so it is very ostentatious haha.

Then invoke the following code in the sidebar sidebar.php:

The code is as follows Copy Code

<?php wp_tag_cloud (' smallest=8&largest=24&number=50 ');?>

Can, 8 is the smallest tag font size (with the least tag), 24 is the largest (with the most of the tag), 50 is the number of tag, you can modify it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.