Make WordPress Core

Ticket #18832: 18832.2.diff

File 18832.2.diff, 3.2 KB (added by tar.gz, 14 years ago)

improved version as per comment 5+6

  • wp-includes/general-template.php

     
    863863                'type' => 'monthly', 'limit' => '',
    864864                'format' => 'html', 'before' => '',
    865865                'after' => '', 'show_post_count' => false,
    866                 'echo' => 1
     866                'echo' => 1, 'order' => 'DESC'
    867867        );
    868868
    869869        $r = wp_parse_args( $args, $defaults );
    870870        extract( $r, EXTR_SKIP );
    871 
     871                               
    872872        if ( '' == $type )
    873873                $type = 'monthly';
    874874
     
    877877                $limit = ' LIMIT '.$limit;
    878878        }
    879879
     880        if ( 'ASC' != strtoupper( $order ) ) {
     881                $order = 'DESC';
     882        }
     883
    880884        // this is what will separate dates on weekly archive links
    881885        $archive_week_separator = '–';
    882886
     
    903907        $output = '';
    904908
    905909        if ( 'monthly' == $type ) {
    906                 $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";
     910                $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";
    907911                $key = md5($query);
    908912                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    909913                if ( !isset( $cache[ $key ] ) ) {
     
    925929                        }
    926930                }
    927931        } elseif ('yearly' == $type) {
    928                 $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";
     932                $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";
    929933                $key = md5($query);
    930934                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    931935                if ( !isset( $cache[ $key ] ) ) {
     
    946950                        }
    947951                }
    948952        } elseif ( 'daily' == $type ) {
    949                 $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";
     953                $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";
    950954                $key = md5($query);
    951955                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    952956                if ( !isset( $cache[ $key ] ) ) {
     
    969973                }
    970974        } elseif ( 'weekly' == $type ) {
    971975                $week = _wp_mysql_week( '`post_date`' );
    972                 $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";
     976                $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";
    973977                $key = md5($query);
    974978                $cache = wp_cache_get( 'wp_get_archives' , 'general');
    975979                if ( !isset( $cache[ $key ] ) ) {