Full file’s source available here without line numbers
// out of the b2 loop
function list_cats($optionall = 1, $all = ‘All’, $sort_column = ‘ID’, $sort_order = ‘asc’,
$file = ‘blah’, $list = true, $optiondates = 0, $optioncount = 0, $hide_empty = 1,
$before=‘<li>’, $after=‘</li>’, $currentCat = ‘’, $beforeCurrent =‘<li class=“current”>’) {
global $tablecategories, $tableposts, $querycount, $wpdb;
global $pagenow;
global $querystring_start, $querystring_equal, $querystring_separator;
if (($file 'blah') || ($file ‘’)) {
$file = $pagenow;
}
$sort_column = ‘cat_’.$sort_column;
$query = “ SELECT cat_ID, cat_name,”;
$query .= “ COUNT($tableposts.ID) AS cat_count,”;
$query .= “ DAYOFMONTH) AS lastday, MONTH) AS lastmonth”;
$query .= “ FROM $tablecategories LEFT JOIN $tableposts ON cat_ID = post_category”;
$query .= “ WHERE cat_ID > 0 “;
$query .= “ GROUP BY post_category “;
if (intval($hide_empty) 1) {
$query .= " HAVING cat_count > 0";
}
$query .= " ORDER BY $sort_column $sort_order, post_date DESC";
$categories = $wpdb->get_results($query);
if (!$categories) {
//before and after default to the list values.
if (!$list) {
$before = '';
$after = '</br>';
}
//no if($list), just use the before and after var's
echo $before . "No categories" . $after . "\n";
return;
}
++$querycount;
if (intval($optionall) 1) {
$all = apply_filters(‘list_cats’, $all);
$link = ‘<a href=”’.$file.$querystring_start.‘cat’.$querystring_equal.‘all”><span>’.$all.‘</span></a>’;
//no if($list), just use the before and after var’s
echo ‘\n\t’ . $before . $link . $after ;
}
foreach ($categories as $category) {
$cat_name = apply_filters(‘list_cats’, $category->cat_name);
$link = ‘<a href=”’.$file.$querystring_start.‘cat’.$querystring_equal.$category->cat_ID. ‘”><span>’;
$link .= stripslashes($cat_name).‘</span></a>’;
if (intval($optioncount) 1) {
$link .= ' ('.$category->cat_count.')';
}
if (intval($optiondates) 1) {
$link .= ‘ ’.$category
}
//no if($list), just use the before and after var’s
//new feature: the ‘beforeCurrent’ gets used if the category matches $currentCat
if( $currentCat == $cat_name ) {
echo “\t” . $beforeCurrent . $link . $after . “\n”;
} else {
echo “\t” . $before . $link . $after . “\n”;
}
}
}
Similar Posts:
- None Found
Awesome! I was just reading that ALA article the other day and was thinking about playing around with it to see if the effect was really worth the effort. After seeing your implementation, I stand convinced. Nice work.
One question: Is your “Huddled Messes” category a Fruedian Slip or a rather comical play on words?
After having played around with Word Press, do you objectively prefer it to Movable Type (neverminding the Open Source characteristic)? I’m finally down with all things MT, so I probably won’t change (I don’t have the free time to keep learning the latest and greatest software packages), but I’m curious what you see the pros/cons to be.
Huddled Messes is a purposeful play on words.
Honestly, the big thing for me is the fact that it’s PHP. I’m just that much more comfortable in PHP than in perl. So far as people using Movable Type switching to WordPress, I’d have to say wait. It’s still a 0.x release, and it shows: they are still making fairly substantial changes to how things work on a regular basis. So much so that I’ve downloaded stuff from CVS three times since I’ve installed this just to get new features that I “needed”
... and still half my links don’t work [
]