From 9add97ebf906677991a31534dd7b58dc096247b7 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Fri, 24 Aug 2012 20:50:22 +0000 Subject: [PATCH] Add 'order' to wp_get_archives(). props tar.gz. fixes #18832. git-svn-id: https://develop.svn.wordpress.org/trunk@21610 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/general-template.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index dbdea16af9..1992a7a58e 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -869,7 +869,7 @@ function wp_get_archives($args = '') { 'type' => 'monthly', 'limit' => '', 'format' => 'html', 'before' => '', 'after' => '', 'show_post_count' => false, - 'echo' => 1 + 'echo' => 1, 'order' => 'DESC', ); $r = wp_parse_args( $args, $defaults ); @@ -883,6 +883,10 @@ function wp_get_archives($args = '') { $limit = ' LIMIT '.$limit; } + $order = strtoupper( $order ); + if ( $order !== 'ASC' ) + $order = 'DESC'; + // this is what will separate dates on weekly archive links $archive_week_separator = '–'; @@ -909,7 +913,7 @@ function wp_get_archives($args = '') { $output = ''; if ( 'monthly' == $type ) { - $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"; + $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"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { @@ -931,7 +935,7 @@ function wp_get_archives($args = '') { } } } elseif ('yearly' == $type) { - $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"; + $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"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { @@ -952,7 +956,7 @@ function wp_get_archives($args = '') { } } } elseif ( 'daily' == $type ) { - $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"; + $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"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) { @@ -975,7 +979,7 @@ function wp_get_archives($args = '') { } } elseif ( 'weekly' == $type ) { $week = _wp_mysql_week( '`post_date`' ); - $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` DESC $limit"; + $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"; $key = md5($query); $cache = wp_cache_get( 'wp_get_archives' , 'general'); if ( !isset( $cache[ $key ] ) ) {