diff options
Diffstat (limited to 'weighted_categories.php')
-rw-r--r-- | weighted_categories.php | 35 |
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 | /* | ||
3 | Plugin Name: Weighted Categories | ||
4 | Plugin URI: http://mike.crute.org/blog/ | ||
5 | Description: Template tag to display a weighted list of category links. | ||
6 | Version: 2.1 | ||
7 | Author: Mike Crute (copied from Matt Kingston) | ||
8 | Author URI: http://mike.crute.org (original author http://hitormiss.org) | ||
9 | */ | ||
10 | function 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 | ||