Advertisement
miriamdepaula

WordPress: Colored Tag Cloud by Font Size

Dec 9th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.71 KB | None | 0 0
  1. <div id="tagCloud">
  2.   <ul>
  3.     <?php
  4.       $arr = wp_tag_cloud(array(
  5.         'smallest'   => 8,          // font size for the least used tag
  6.         'largest'    => 40,         // font size for the most used tag
  7.         'unit'       => 'px',       // font sizing choice (pt, em, px, etc)
  8.         'number'     => 200,        // maximum number of tags to show
  9.         'format'     => 'array',    // flat, list, or array. flat = spaces between; list = in li tags; array = does not echo results, returns array
  10.         'separator'  => '',         //
  11.         'orderby'    => 'name',     // name = alphabetical by name; count = by popularity
  12.         'order'      => 'RAND',     // starting from A, or starting from highest count
  13.         'exclude'    => '',         // ID's of tags to exclude, displays all except these
  14.         'include'    => '',         // ID's of tags to include, displays none except these
  15.         'link'       => 'view',     // view = links to tag view; edit = link to edit tag
  16.         'taxonomy'   => 'post_tag', // post_tag, link_category, category - create tag clouds of any of these things
  17.         'echo'       => true        // set to false to return an array, not echo it
  18.       ));
  19.       foreach ($arr as $value) {
  20.         $ptr1 = strpos($value,'font-size:');
  21.         $ptr2 = strpos($value,'px');
  22.         $px = round(substr($value,$ptr1+10,$ptr2-$ptr1-10));
  23.         $value = substr($value, 0, $ptr1+10) . $px . substr($value, $ptr2);
  24.         $ptr1 = strpos($value, "class=");
  25.         $value = substr($value, 0, $ptr1+7) . 'color-' . $px . ' ' . substr($value, $ptr1+7);
  26.         echo '<li>' . $value . '</li> ';
  27.       }
  28.     ?>
  29.   </ul>
  30. </div>
  31.  
  32. // CSS Style - Example
  33.  
  34. .color-29 {
  35.    color: red;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement