get_var("SELECT ID FROM $wpdb->posts WHERE post_date <'" . current_time('mysql') . "' AND post_status='publish' AND post_type='post' AND post_password='' ORDER BY post_date DESC LIMIT 1"); if(empty($output)){ $output = ''; $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'hfy_archives_%'"); // Get all of the months that have posts $monthquery = "SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, count(ID) as posts FROM " . $wpdb->posts . " WHERE post_date <'" . current_time('mysql') . "' AND post_status='publish' AND post_type='post' AND post_password='' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC"; $monthresults = $wpdb->get_results($monthquery); if ($monthresults) { // Loop through each month foreach ($monthresults as $monthresult) { $thismonth = zeroise($monthresult->month, 2); $thisyear = $monthresult->year; // Get all of the posts for the current month $postquery = "SELECT ID, post_date, post_title, comment_count FROM " . $wpdb->posts . " WHERE post_date LIKE '$thisyear-$thismonth-%' AND post_date AND post_status='publish' AND post_type='post' AND post_password='' ORDER BY post_date DESC"; $postresults = $wpdb->get_results($postquery); if ($postresults) { // The month year title things $text = sprintf('%s %d', $month[zeroise($monthresult->month,2)], $monthresult->year); $text_id = strtolower(str_replace(" ","",$text)); $postcount = count($postresults); if($postcount=="1") $postcount_text = "post"; else $postcount_text = "posts"; $output .= "

" . $text . " (" . count($postresults) . " ".$postcount_text." )

"; $output .= "\n\n"; } } update_option('hfy_archives_'.$lastpost,$output); }else{ $output = ''. __('Not Found','Luno') .' '. __("Sorry, but you are looking for something that isn't here.","Luno") .''; } } echo $output; //echo archives end ?>