Changeset 23385
- Timestamp:
- 02/04/2013 01:54:15 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/general-template.php
r23355 r23385 913 913 } 914 914 915 //filters916 915 $where = apply_filters( 'getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'", $r ); 917 916 $join = apply_filters( 'getarchives_join', '', $r ); … … 919 918 $output = ''; 920 919 920 $last_changed = wp_cache_get( 'last_changed', 'posts' ); 921 if ( ! $last_changed ) { 922 $last_changed = 1; 923 wp_cache_set( 'last_changed', $last_changed, 'posts' ); 924 } 925 921 926 if ( 'monthly' == $type ) { 922 927 $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 $order $limit"; 923 $key = md5($query); 924 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 925 if ( !isset( $cache[ $key ] ) ) { 926 $arcresults = $wpdb->get_results($query); 927 $cache[ $key ] = $arcresults; 928 wp_cache_set( 'wp_get_archives', $cache, 'general' ); 929 } else { 930 $arcresults = $cache[ $key ]; 928 $key = md5( $query ); 929 $key = "wp_get_archives:$key:$last_changed"; 930 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 931 $results = $wpdb->get_results( $query ); 932 wp_cache_set( $key, $results, 'posts' ); 931 933 } 932 if ( $ arcresults ) {934 if ( $results ) { 933 935 $afterafter = $after; 934 foreach ( (array) $ arcresults as $arcresult ) {935 $url = get_month_link( $ arcresult->year, $arcresult->month );936 foreach ( (array) $results as $result ) { 937 $url = get_month_link( $result->year, $result->month ); 936 938 /* translators: 1: month name, 2: 4-digit year */ 937 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($ arcresult->month), $arcresult->year);939 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); 938 940 if ( $show_post_count ) 939 $after = ' ('.$ arcresult->posts.')' . $afterafter;941 $after = ' ('.$result->posts.')' . $afterafter; 940 942 $output .= get_archives_link($url, $text, $format, $before, $after); 941 943 } … … 943 945 } elseif ('yearly' == $type) { 944 946 $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 $order $limit"; 945 $key = md5($query); 946 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 947 if ( !isset( $cache[ $key ] ) ) { 948 $arcresults = $wpdb->get_results($query); 949 $cache[ $key ] = $arcresults; 950 wp_cache_set( 'wp_get_archives', $cache, 'general' ); 951 } else { 952 $arcresults = $cache[ $key ]; 947 $key = md5( $query ); 948 $key = "wp_get_archives:$key:$last_changed"; 949 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 950 $results = $wpdb->get_results( $query ); 951 wp_cache_set( $key, $results, 'posts' ); 953 952 } 954 if ( $arcresults) {953 if ( $results ) { 955 954 $afterafter = $after; 956 foreach ( (array) $ arcresults as $arcresult) {957 $url = get_year_link($ arcresult->year);958 $text = sprintf('%d', $ arcresult->year);955 foreach ( (array) $results as $result) { 956 $url = get_year_link($result->year); 957 $text = sprintf('%d', $result->year); 959 958 if ($show_post_count) 960 $after = ' ('.$ arcresult->posts.')' . $afterafter;959 $after = ' ('.$result->posts.')' . $afterafter; 961 960 $output .= get_archives_link($url, $text, $format, $before, $after); 962 961 } … … 964 963 } elseif ( 'daily' == $type ) { 965 964 $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 $order $limit"; 966 $key = md5($query); 967 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 968 if ( !isset( $cache[ $key ] ) ) { 969 $arcresults = $wpdb->get_results($query); 970 $cache[ $key ] = $arcresults; 971 wp_cache_set( 'wp_get_archives', $cache, 'general' ); 972 } else { 973 $arcresults = $cache[ $key ]; 965 $key = md5( $query ); 966 $key = "wp_get_archives:$key:$last_changed"; 967 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 968 $results = $wpdb->get_results( $query ); 969 $cache[ $key ] = $results; 970 wp_cache_set( $key, $results, 'posts' ); 974 971 } 975 if ( $ arcresults ) {972 if ( $results ) { 976 973 $afterafter = $after; 977 foreach ( (array) $ arcresults as $arcresult ) {978 $url = get_day_link($ arcresult->year, $arcresult->month, $arcresult->dayofmonth);979 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $ arcresult->year, $arcresult->month, $arcresult->dayofmonth);974 foreach ( (array) $results as $result ) { 975 $url = get_day_link($result->year, $result->month, $result->dayofmonth); 976 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); 980 977 $text = mysql2date($archive_day_date_format, $date); 981 978 if ($show_post_count) 982 $after = ' ('.$ arcresult->posts.')'.$afterafter;979 $after = ' ('.$result->posts.')'.$afterafter; 983 980 $output .= get_archives_link($url, $text, $format, $before, $after); 984 981 } … … 987 984 $week = _wp_mysql_week( '`post_date`' ); 988 985 $query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit"; 989 $key = md5($query); 990 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 991 if ( !isset( $cache[ $key ] ) ) { 992 $arcresults = $wpdb->get_results($query); 993 $cache[ $key ] = $arcresults; 994 wp_cache_set( 'wp_get_archives', $cache, 'general' ); 995 } else { 996 $arcresults = $cache[ $key ]; 986 $key = md5( $query ); 987 $key = "wp_get_archives:$key:$last_changed"; 988 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 989 $results = $wpdb->get_results( $query ); 990 wp_cache_set( $key, $results, 'posts' ); 997 991 } 998 992 $arc_w_last = ''; 999 993 $afterafter = $after; 1000 if ( $ arcresults ) {1001 foreach ( (array) $ arcresults as $arcresult ) {1002 if ( $ arcresult->week != $arc_w_last ) {1003 $arc_year = $ arcresult->yr;1004 $arc_w_last = $ arcresult->week;1005 $arc_week = get_weekstartend($ arcresult->yyyymmdd, get_option('start_of_week'));994 if ( $results ) { 995 foreach ( (array) $results as $result ) { 996 if ( $result->week != $arc_w_last ) { 997 $arc_year = $result->yr; 998 $arc_w_last = $result->week; 999 $arc_week = get_weekstartend($result->yyyymmdd, get_option('start_of_week')); 1006 1000 $arc_week_start = date_i18n($archive_week_start_date_format, $arc_week['start']); 1007 1001 $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); 1008 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $ arcresult->week);1002 $url = sprintf('%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week); 1009 1003 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 1010 1004 if ($show_post_count) 1011 $after = ' ('.$ arcresult->posts.')'.$afterafter;1005 $after = ' ('.$result->posts.')'.$afterafter; 1012 1006 $output .= get_archives_link($url, $text, $format, $before, $after); 1013 1007 } … … 1017 1011 $orderby = ('alpha' == $type) ? 'post_title ASC ' : 'post_date DESC '; 1018 1012 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; 1019 $key = md5($query); 1020 $cache = wp_cache_get( 'wp_get_archives' , 'general'); 1021 if ( !isset( $cache[ $key ] ) ) { 1022 $arcresults = $wpdb->get_results($query); 1023 $cache[ $key ] = $arcresults; 1024 wp_cache_set( 'wp_get_archives', $cache, 'general' ); 1025 } else { 1026 $arcresults = $cache[ $key ]; 1013 $key = md5( $query ); 1014 $key = "wp_get_archives:$key:$last_changed"; 1015 if ( ! $results = wp_cache_get( $key, 'posts' ) ) { 1016 $results = $wpdb->get_results( $query ); 1017 wp_cache_set( $key, $results, 'posts' ); 1027 1018 } 1028 if ( $ arcresults ) {1029 foreach ( (array) $ arcresults as $arcresult ) {1030 if ( $ arcresult->post_date != '0000-00-00 00:00:00' ) {1031 $url = get_permalink( $ arcresult );1032 if ( $ arcresult->post_title )1033 $text = strip_tags( apply_filters( 'the_title', $ arcresult->post_title, $arcresult->ID ) );1019 if ( $results ) { 1020 foreach ( (array) $results as $result ) { 1021 if ( $result->post_date != '0000-00-00 00:00:00' ) { 1022 $url = get_permalink( $result ); 1023 if ( $result->post_title ) 1024 $text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) ); 1034 1025 else 1035 $text = $ arcresult->ID;1026 $text = $result->ID; 1036 1027 $output .= get_archives_link($url, $text, $format, $before, $after); 1037 1028 }
Note: See TracChangeset
for help on using the changeset viewer.