From 7fee5dee72ea0a35b214de0299698a29b19dbce6 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 25 Feb 2009 17:09:29 +0000 Subject: [PATCH] Revert get_calendar() changes from [10602]. Broke calendar links. see #8351 git-svn-id: https://develop.svn.wordpress.org/trunk@10646 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/general-template.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index e527062a32..6081ead91e 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -927,7 +927,7 @@ function get_calendar($initial = true) { ob_start(); // Quick check. If we have no posts at all, abort! if ( !$posts ) { - $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); + $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); if ( !$gotsome ) return; } @@ -961,16 +961,16 @@ function get_calendar($initial = true) { $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); // Get the next and previous month and year with at least one post - $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts WHERE post_date < '$thisyear-$thismonth-01' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 1"); - $last_day = date('t'); - $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year + $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year FROM $wpdb->posts - WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' + WHERE post_date > '$thisyear-$thismonth-01' + AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date ASC LIMIT 1"); @@ -1025,7 +1025,8 @@ function get_calendar($initial = true) { // Get days with posts $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) - FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' + FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' + AND YEAR(post_date) = '$thisyear' AND post_type = 'post' AND post_status = 'publish' AND post_date < '" . current_time('mysql') . '\'', ARRAY_N); if ( $dayswithposts ) { @@ -1044,7 +1045,8 @@ function get_calendar($initial = true) { $ak_titles_for_day = array(); $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " ."FROM $wpdb->posts " - ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " + ."WHERE YEAR(post_date) = '$thisyear' " + ."AND MONTH(post_date) = '$thismonth' " ."AND post_date < '".current_time('mysql')."' " ."AND post_type = 'post' AND post_status = 'publish'" );