function mu_tag_cloud($custom = "") { global $wpdb, $table_prefix, $Mu_tags; $defaults = array('maxsize' => $Mu_tags->TagOpt['tag_max_size'], 'minsize' => $Mu_tags->TagOpt['tag_min_size'], 'mincolor' => $Mu_tags->TagOpt['tag_min_color'], 'maxcolor' => $Mu_tags->TagOpt['tag_max_color'], 'limit' => $Mu_tags->TagOpt['limit_tags'], 'exclude' => $Mu_tags->TagOpt['exclude'], 'bexclude' => $Mu_tags->TagOpt['bexclude'], 'cssclass' => $Mu_tags->TagOpt['css_class'], 'orderby' => $Mu_tags->TagOpt['tag_sort_format'], 'daysback' => $Mu_tags->TagOpt['daysback'], 'includecats' => $Mu_tags->TagOpt['include_cats']); extract($defaults); //If custom values are found use them insead if (is_array($custom)) { extract($custom); $customvals = true; } else { $customvals = false; } $notagsmsg = '<ul><li>No tags found...</li></ul>'; $tag_list = $Mu_tags->get_global_tags($values = array('limit' => $limit, 'exclude' => $exclude, 'bexclude' => $bexclude, 'orderby' => $orderby, 'daysback' => $daysback, 'includecats' => $includecats), $customvals); if ($tag_list) { foreach ($tag_list as $tmp) { $tags[$tmp->tag] = $tmp->cnnt; } // get the largest and smallest array values $max_qty = max(array_values($tags)); $min_qty = min(array_values($tags)); // find the range of values $spread = $max_qty - $min_qty; if (0 == $spread) { // we don't want to divide by zero $spread = 1; } // determine the font-size increment // this is the increase per tag quantity (times used) $step = ($maxsize - $minsize) / $spread; // loop through our tag array foreach ($tag_list as $tag) { $link = $tag->category_nicename; $key = $tag->tag; $value = $tag->cnnt; // calculate CSS font-size // find the $value in excess of $min_qty // multiply by the font-size increment ($size) // and add the $min_size set above $size = $minsize + ($value - $min_qty) * $step; // uncomment if you want sizes in whole %: //$size = ceil($size); $color_weight = round(99 * ($size - $minsize) / ($maxsize - $minsize) + 1); echo '<a href="/' . $Mu_tags->TagOpt['tag_base'] . '/' . $link . '" class="' . $cssclass . '" style="font-size: ' . $size . '' . $Mu_tags->TagOpt['tag_size_format'] . '; color: ' . ColorWeight($color_weight, $mincolor, $maxcolor) . ';"'; echo ' title="' . linktitle($key, $value) . '"'; echo '>' . $key . '</a> '; } } else { echo $notagsmsg; } }
/** * Generate Tag Cloud - function to create the links for the cloud based on the args from the tw() function * * $tagscats = prefetched tag array (get_tags() & get_categories()) * $args['format'] = 'flat' => whitespace separated, 'list' => UL, 'array' => array() * $args['orderby'] = 'name', 'count', 'rand' */ function generate_tag_cloud($tagscats, $args = '') { global $wp_rewrite; $defaults = array('title' => 'Tags', 'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => '', 'minnum' => 0, 'maxnum' => 100, 'format' => 'flat', 'orderby' => 'name', 'order' => 'ASC', 'exclude' => '', 'include' => '', 'mincolor' => '', 'maxcolor' => '', 'showcount' => 'no', 'showtags' => 'yes', 'showcats' => 'no', 'empty' => 'no', 'widget' => 'yes'); $widget = $defaults['widget']; if ('yes' == $widget) { $options = get_option('widget_tw'); } else { $options = get_option('template_tw'); } $args = wp_parse_args($args, $options, $defaults); extract($args); if (!$tagscats) { return; } $counts = $tag_links = array(); if ($orderby == 'rand') { shuffle($tagscats); } foreach ((array) $tagscats as $tag) { $counts[$tag->name] = $tag->count; $cat = $tag->taxonomy; if ('category' == $cat) { $tag_links[$tag->name] = get_category_link($tag->term_id); } else { $tag_links[$tag->name] = get_tag_link($tag->term_id); } if (is_wp_error($tag_links[$tag->name])) { return $tag_links[$tag->name]; } $tag_ids[$tag->name] = $tag->term_id; } $min_count = min($counts); $spread = max($counts) - $min_count; if ($spread <= 0) { $spread = 1; } $font_spread = $largest - $smallest; if ($font_spread <= 0) { $font_spread = 1; } $font_step = $font_spread / $spread; // SQL cannot save you; this is a second (potentially different) sort on a subset of data. if ($orderby == 'name') { uksort($counts, 'strnatcasecmp'); } else { if ('count' == $orderby) { asort($counts); } } if ($order == 'DESC') { $counts = array_reverse($counts, true); } $a = array(); $rel = is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ? ' rel="tag"' : ''; foreach ($counts as $tag => $count) { if ($largest == $smallest) { $tag_weight = $largest; } else { $tag_weight = $smallest + ($count - $min_count) * $font_step; } $diff = $largest - $smallest; if ($diff <= 0) { $diff = 1; } if ($showcount == 'yes') { $postcount = '(' . $count . ')'; } $color_weight = round(99 * ($tag_weight - $smallest) / $diff + 1); $tag_color = ColorWeight($color_weight, $mincolor, $maxcolor); $tag_id = $tag_ids[$tag]; $tag_link = clean_url($tag_links[$tag]); $tag = wp_specialchars($tag); if ($format == 'list') { $a[] = "<li><a href=\"{$tag_link}\" title=\"" . attribute_escape(sprintf(__('%d topics'), $count)) . "\"{$rel}\n\t\t\t\t\t\t\tstyle=\"font-size: " . $tag_weight . "{$unit};" . (isset($tag_color) ? " color: {$tag_color};" : "") . "\">{$tag}</a>" . ('yes' == $showcount ? " {$postcount}" : "") . "</li>"; } else { if ($format == 'drop') { $a[] = "<option value='{$tag_link}'>{$tag}" . ('yes' == $showcount ? " {$postcount}" : "") . "</option>"; } else { $a[] = "<a href=\"{$tag_link}\" class=\"tw-tag tag-link-{$tag_id}\" title=\"" . attribute_escape(sprintf(__('%d topics'), $count)) . "\"{$rel} style=\"font-size: " . $tag_weight . "{$unit};" . (isset($tag_color) ? " color: {$tag_color};" : "") . "\">{$tag}" . "</a>" . ('yes' == $showcount ? " {$postcount}" : ""); } } } switch ($format) { case 'array': $return =& $a; break; case 'list': $return = '<ul class="tw-tag-cloud">'; $return .= join("\n\t", $a); $return .= '</ul>'; break; case 'drop': $return = '<select name="tw-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">' . '<option value="">Select Tag</option>' . join("\n\t", $a) . '</option>' . '</select>'; break; default: $return = join("\n", $a); break; } return apply_filters('generate_tag_cloud', $return, $tagscats, $args); }