From a1813a91203051d590234f4e738d42cdf319b6ca Mon Sep 17 00:00:00 2001 From: mikelittle Date: Mon, 4 Aug 2003 21:25:35 +0000 Subject: [PATCH] Added list_cats() options to dropdown_cats() sort order, post count, last date, etc. git-svn-id: http://svn.automattic.com/wordpress/trunk@291 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- b2-include/b2template.functions.php | 32 +++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index b4e796f18..26c806556 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -857,19 +857,43 @@ function the_category_head($before='', $after='') { } // out of the b2 loop -function dropdown_cats($optionall = 1, $all = 'All') { - global $cat, $tablecategories, $querycount, $wpdb; - $categories = $wpdb->get_results("SELECT cat_ID, cat_name FROM $tablecategories"); +function dropdown_cats($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', + $optiondates = 0, $optioncount = 0, $hide_empty = 1) { + global $cat, $tablecategories, $tableposts, $querycount, $wpdb; + $sort_column = 'cat_'.$sort_column; + + $query = " SELECT cat_ID, cat_name,"; + $query .= " COUNT($tableposts.ID) AS cat_count,"; + $query .= " DAYOFMONTH(MAX(post_date)) AS lastday, MONTH(MAX(post_date)) 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); ++$querycount; echo "\n"; }