summaryrefslogtreecommitdiff
path: root/weighted_categories.php
diff options
context:
space:
mode:
Diffstat (limited to 'weighted_categories.php')
-rw-r--r--weighted_categories.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/weighted_categories.php b/weighted_categories.php
new file mode 100644
index 0000000..d391472
--- /dev/null
+++ b/weighted_categories.php
@@ -0,0 +1,35 @@
1<?php
2/*
3Plugin Name: Weighted Categories
4Plugin URI: http://mike.crute.org/blog/
5Description: Template tag to display a weighted list of category links.
6Version: 2.1
7Author: Mike Crute (copied from Matt Kingston)
8Author URI: http://mike.crute.org (original author http://hitormiss.org)
9*/
10function weighted_categories($smallest=10, $largest=40, $unit='pt')
11{
12 // get the categories and build an array from them
13 $cats = get_categories('type=post');
14
15 foreach ($cats as $cat)
16 {
17 $catname = $cat->cat_name;
18 $counts[$catname] = $cat->category_count;
19 $catlinks[$catname] = $cat->category_nicename;
20 }
21
22 // calculate the font sizes but always fall back to a safe value
23 $spread = (max($counts) - min($counts)) <= 0 ? max($counts) - min($counts) : 1;
24 $fontspread = ($largest - $smallest) <= 0 ? $largest - $smallest : 1;
25 $fontstep = $spread / $fontspread;
26
27 // print the links out
28 foreach ($counts as $catname => $count)
29 {
30 $catlink = $catlinks[$catname];
31 $fontsize = ($smallest + ($count/$fontstep)) . $unit;
32 echo("<a href='$catlink' title='$count entries' style='font-size: $fontsize;'>$catname</a>\n");
33 }
34}
35?> \ No newline at end of file