Ticket #8351: general-template.php.diff
File general-template.php.diff, 4.5 KB (added by , 15 years ago) |
---|
-
general-template.php
750 750 $output = ''; 751 751 752 752 if ( 'monthly' == $type ) { 753 $query = "SELECT DISTINCTYEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit";753 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC $limit"; 754 754 $key = md5($query); 755 755 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 756 756 if ( !isset( $cache[ $key ] ) ) { … … 771 771 } 772 772 } 773 773 } elseif ('yearly' == $type) { 774 $query = "SELECT DISTINCTYEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit";774 $query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date DESC $limit"; 775 775 $key = md5($query); 776 776 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 777 777 if ( !isset( $cache[ $key ] ) ) { … … 792 792 } 793 793 } 794 794 } elseif ( 'daily' == $type ) { 795 $query = "SELECT DISTINCTYEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit";795 $query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC $limit"; 796 796 $key = md5($query); 797 797 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 798 798 if ( !isset( $cache[ $key ] ) ) { … … 913 913 ob_start(); 914 914 // Quick check. If we have no posts at all, abort! 915 915 if ( !$posts ) { 916 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESCLIMIT 1");916 $gotsome = $wpdb->get_var("SELECT ID from $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 1"); 917 917 if ( !$gotsome ) 918 918 return; 919 919 } … … 947 947 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 948 948 949 949 // Get the next and previous month and year with at least one post 950 $previous = $wpdb->get_row("SELECT DISTINCTMONTH(post_date) AS month, YEAR(post_date) AS year950 $previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 951 951 FROM $wpdb->posts 952 952 WHERE post_date < '$thisyear-$thismonth-01' 953 953 AND post_type = 'post' AND post_status = 'publish' 954 954 ORDER BY post_date DESC 955 955 LIMIT 1"); 956 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year 956 $last_day = date('t', $unixmonth); 957 $next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year 957 958 FROM $wpdb->posts 958 WHERE post_date > '$thisyear-$thismonth-01' 959 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 959 WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59' 960 960 AND post_type = 'post' AND post_status = 'publish' 961 961 ORDER BY post_date ASC 962 962 LIMIT 1"); … … 1011 1011 1012 1012 // Get days with posts 1013 1013 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 1014 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth' 1015 AND YEAR(post_date) = '$thisyear' 1014 FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' 1016 1015 AND post_type = 'post' AND post_status = 'publish' 1017 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);1016 AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N); 1018 1017 if ( $dayswithposts ) { 1019 1018 foreach ( (array) $dayswithposts as $daywith ) { 1020 1019 $daywithpost[] = $daywith[0]; … … 1031 1030 $ak_titles_for_day = array(); 1032 1031 $ak_post_titles = $wpdb->get_results("SELECT post_title, DAYOFMONTH(post_date) as dom " 1033 1032 ."FROM $wpdb->posts " 1034 ."WHERE YEAR(post_date) = '$thisyear' " 1035 ."AND MONTH(post_date) = '$thismonth' " 1036 ."AND post_date < '".current_time('mysql')."' " 1033 ."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' " 1034 ."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' " 1037 1035 ."AND post_type = 'post' AND post_status = 'publish'" 1038 1036 ); 1039 1037 if ( $ak_post_titles ) {