[wp-trac] [WordPress Trac] #5191: Style tag cloud by color

WordPress Trac wp-trac at lists.automattic.com
Sat Oct 13 15:48:25 GMT 2007


#5191: Style tag cloud by color
-------------------------+--------------------------------------------------
 Reporter:  webrocker    |       Owner:  anonymous
     Type:  enhancement  |      Status:  new      
 Priority:  normal       |   Milestone:  2.5      
Component:  General      |     Version:           
 Severity:  normal       |    Keywords:           
-------------------------+--------------------------------------------------
 After looking into #5131, #5171, and #5172 I'd like to see the
 (additional) ability to style the tag cloud between two colors - like it
 is possible with the UTW Plugin ([http://www.neato.co.nz/wp-
 content/plugins/UltimateTagWarrior/ultimate-tag-warrior-help-
 themes.html#tagcloud]).
 With the above tickets we have the ability to apply individual classes per
 tag and ignore the font-size thing, which in theory should be enough for a
 color-weighted tag-cloud. But with every additional tag one would have to
 re-define the css-stylesheet - not very Wordpressy.[[BR]][[BR]]

 It would be nice to have additional parameters in the wp_tag_cloud()
 function for the start- and end-color, and have the function "render" the
 in-between colors... like
 wp_tag_cloud('...&startC=#990022&endC=#1166CC');[[BR]][[BR]]

 I guess since the font-size is already calculated in relation to the
 amount and order of the tag shown, it shouldn't be too hard to tweak the
 function to do the same for hex-color-codes?[[BR]][[BR]]

 The difficulty is to calculate the right in-between color-codes... I have
 tried to understand what is done in the appr. function (ultimate-tag-
 warrior-core.php) in UTW, but frankly, failed to understand it (and the
 comment at the beginning isn't encouraging either):
 {{{
 /* This is pretty filthy.  Doing math in hex is much too weird.  It's more
 likely to work,  this way! */
         function GetColorForWeight($weight) {
                 global $maxtagcolour, $mintagcolour;
                 if ($weight) {
                         $weight = $weight/100;

                         $minr = hexdec(substr($mintagcolour, 1, 2));
                         $ming = hexdec(substr($mintagcolour, 3, 2));
                         $minb = hexdec(substr($mintagcolour, 5, 2));

                         $maxr = hexdec(substr($maxtagcolour, 1, 2));
                         $maxg = hexdec(substr($maxtagcolour, 3, 2));
                         $maxb = hexdec(substr($maxtagcolour, 5, 2));

                         $r = dechex(intval((($maxr - $minr) * $weight) +
 $minr));
                         $g = dechex(intval((($maxg - $ming) * $weight) +
 $ming));
                         $b = dechex(intval((($maxb - $minb) * $weight) +
 $minb));

                         if (strlen($r) == 1) $r = "0" . $r;
                         if (strlen($g) == 1) $g = "0" . $g;
                         if (strlen($b) == 1) $b = "0" . $b;

                         return "#$r$g$b";
                 }
         }
 }}}
 [[BR]]
 What do you think?

-- 
Ticket URL: <http://trac.wordpress.org/ticket/5191>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list