get_results("SELECT cat_ID FROM $wpdb->categories WHERE category_count >= $threshold"); $cat_ids = array(); foreach ($cats as $cat) { if ($count < $threshold ) { $cat_ids[] = $cat->cat_ID; } } if (count($cat_ids)) { $exclusion_str .= " AND cat_ID IN (" . join(',', $cat_ids) . ") "; } return $exclusion_str; } /** wp_list_popular_categories - categories of posts more recent then $days_ago days */ function wp_list_recent_categories($args) { add_filter('list_cats_exclusions', 'filter_recent_cats_only'); parse_str($args, $r); $GLOBALS['__better_cat_lists_ago'] = intval($r['days_ago']); $GLOBALS['__better_cat_lists_limit'] = intval($r['cat_limit']); wp_list_cats($args); remove_filter('list_cats_exclusions', 'filter_recent_cats_only'); } function filter_recent_cats_only($exclusion_str ='') { global $wpdb; $ago = date("Y-m-d H:i:s", time() - (60*60*24*$GLOBALS['__better_cat_lists_ago'] )); $limit = $GLOBALS['__better_cat_lists_limit']; $sql = "SELECT wp_post2cat.category_id FROM wp_posts, wp_post2cat " . "WHERE wp_posts.ID = wp_post2cat.post_id AND post_date > '$ago' " . "ORDER BY post_date desc"; $cats = $wpdb->get_results($sql); $cat_ids = array(); foreach ($cats as $cat) { $cat_ids[] = $cat->category_id; } if($limit) { $cat_ids = array_splice($cat_ids, 0, $limit); } if (count($cat_ids)) { $exclusion_str .= " AND cat_ID IN (" . join(',', $cat_ids) . ") "; } return $exclusion_str; } ?>