terms.'.term_ID <> ' . intval($excat) . ' '; } } } $query = "SELECT $wpdb->terms.term_ID AS `id`, $wpdb->terms.name AS `name`, $wpdb->terms.slug AS `nicename`, $wpdb->term_taxonomy.count AS `posts` FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_ID = $wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.taxonomy = 'category' $exclusions GROUP BY $wpdb->terms.term_id ORDER BY posts DESC"; if ($limit != 0) { $query .= " LIMIT ".$limit; } $results = $wpdb->get_results($query); usort($results, 'sort_cat_name'); foreach ($results as $result) { $counts[] = $result->posts; } $min = min($counts); $max = max($counts); $spread = $max - $min; if ($largest != $smallest) { $fontspread = $largest - $smallest; if ($spread != 0) { $fontstep = $fontspread / $spread; } else { $fontstep = 0; } } if ($hot != $cold) { for ($i = 0; $i < 3; $i++) { $coldval[] = hexdec($cold[$i]); $hotval[] = hexdec($hot[$i]); $colorspread[] = hexdec($hot[$i]) - hexdec($cold[$i]); if ($spread != 0) { $colorstep[] = (hexdec($hot[$i]) - hexdec($cold[$i])) / $spread; } else { $colorstep[] = 0; } } } foreach ($results as $result) { $url = get_category_link($result->id); $text = stripslashes($result->name); $fraction = ($result->posts - $min); $fontsize = $smallest + ($fontstep * $fraction); $color = ""; for ($i = 0; $i < 3; $i++) { $color .= dechex($coldval[$i] + ($colorstep[$i] * $fraction)); } $style = "style=\""; if ($largest != $smallest) { $style .= "font-size:".round($fontsize).$unit.";"; } if ($hot != $cold) { $style .= "color:#".$color.";"; } $style .= "\""; echo $before ."posts ." entries\" " .$style .">" .$text ."" .$after ."\n"; } } function heatmap_tags($smallest=10, $largest=36, $unit="pt", $cold="00f", $hot="f00", $before='', $after=' ', $exclude='', $limit=0) { global $querystring_start, $querystring_equal, $querystring_separator, $wpdb; $exclusions = ''; if (!empty($exclude)) { $excats = preg_split('/[\s,]+/',$exclude); if (count($excats)) { foreach ($excats as $excat) { $exclusions .= ' AND '.$wpdb->terms.'.term_ID <> ' . intval($excat) . ' '; } } } $query = "SELECT $wpdb->terms.term_ID AS `id`, $wpdb->terms.name AS `name`, $wpdb->terms.slug AS `nicename`, $wpdb->term_taxonomy.count AS `posts` FROM $wpdb->terms, $wpdb->term_taxonomy WHERE $wpdb->terms.term_ID = $wpdb->term_taxonomy.term_id AND $wpdb->term_taxonomy.taxonomy = 'post_tag' $exclusions GROUP BY $wpdb->terms.term_id ORDER BY posts DESC"; if ($limit != 0) { $query .= " LIMIT ".$limit; } $results = $wpdb->get_results($query); usort($results, 'sort_cat_name'); foreach ($results as $result) { $counts[] = $result->posts; } $min = min($counts); $max = max($counts); $spread = $max - $min; if ($largest != $smallest) { $fontspread = $largest - $smallest; if ($spread != 0) { $fontstep = $fontspread / $spread; } else { $fontstep = 0; } } if ($hot != $cold) { for ($i = 0; $i < 3; $i++) { $coldval[] = hexdec($cold[$i]); $hotval[] = hexdec($hot[$i]); $colorspread[] = hexdec($hot[$i]) - hexdec($cold[$i]); if ($spread != 0) { $colorstep[] = (hexdec($hot[$i]) - hexdec($cold[$i])) / $spread; } else { $colorstep[] = 0; } } } foreach ($results as $result) { $url = get_tag_link($result->id); $text = stripslashes($result->name); $fraction = ($result->posts - $min); $fontsize = $smallest + ($fontstep * $fraction); $color = ""; for ($i = 0; $i < 3; $i++) { $color .= dechex($coldval[$i] + ($colorstep[$i] * $fraction)); } $style = "style=\""; if ($largest != $smallest) { $style .= "font-size:".round($fontsize).$unit.";"; } if ($hot != $cold) { $style .= "color:#".$color.";"; } $style .= "\""; echo $before ."posts ." entries\" " .$style .">" .$text ."" .$after ."\n"; } } function heatmap_archives($smallest=10, $largest=36, $unit="pt", $cold="00f", $hot="f00", $before='', $after=' ') { global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb; $now = current_time('mysql'); $results = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) AS `posts` FROM $wpdb->posts WHERE post_date < '$now' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC" . $limit); foreach ($results as $result) { $counts[] = $result->posts; } $min = min($counts); $max = max($counts); $spread = $max - $min; if ($largest != $smallest) { $fontspread = $largest - $smallest; if ($spread != 0) { $fontstep = $fontspread / $spread; } else { $fontstep = 0; } } if ($hot != $cold) { for ($i = 0; $i < 3; $i++) { $coldval[] = hexdec($cold[$i]); $hotval[] = hexdec($hot[$i]); $colorspread[] = hexdec($hot[$i]) - hexdec($cold[$i]); if ($spread != 0) { $colorstep[] = (hexdec($hot[$i]) - hexdec($cold[$i])) / $spread; } else { $colorstep[] = 0; } } } foreach ($results as $result) { $url = get_month_link($result->year, $result->month); $text = sprintf('%s %d', $month[zeroise($result->month,2)], $result->year); $fraction = ($result->posts - $min); $fontsize = $smallest + ($fontstep * $fraction); $color = ""; for ($i = 0; $i < 3; $i++) { $color .= dechex($coldval[$i] + ($colorstep[$i] * $fraction)); } $style = "style=\""; if ($largest != $smallest) { $style .= "font-size:".round($fontsize).$unit.";"; } if ($hot != $cold) { $style .= "color:#".$color.";"; } $style .= "\""; echo $before ."posts ." entries\" " .$style .">" .$text ."" .$after ."\n"; } } function sort_cat_name($a, $b) { if ($a->name == $b->name) return 0; return ($a->name < $b->name) ? -1 : 1; } ?>