Ticket #3110: 3110.diff

File 3110.diff, 3.9 kB (added by westi, 2 years ago)

Fix wp_get_archives show_post_count

  • wp-includes/general-template.php

    old new  
    323323                        $afterafter = $after; 
    324324                        foreach ( $arcresults as $arcresult ) { 
    325325                                $url    = get_month_link($arcresult->year,      $arcresult->month); 
    326                                 if ( $show_post_count ) { 
    327                                        $text = sprintf('%s %d', $wp_locale->get_month($arcresult->month), $arcresult->year); 
     326                                $text = sprintf('%s %d', $wp_locale->get_month($arcresult->month), $arcresult->year); 
     327                                if ( $show_post_count )  
    328328                                        $after = ' ('.$arcresult->posts.')' . $afterafter; 
    329                                 } else { 
    330                                         $text = sprintf('%s %d', $wp_locale->get_month($arcresult->month), $arcresult->year); 
    331                                 } 
    332329                                echo get_archives_link($url, $text, $format, $before, $after); 
    333330                        } 
    334331                } 
     
    338335            $afterafter = $after; 
    339336            foreach ($arcresults as $arcresult) { 
    340337                            $url = get_year_link($arcresult->year); 
    341                                 if ($show_post_count) { 
    342                     $text = sprintf('%d', $arcresult->year); 
     338                $text = sprintf('%d', $arcresult->year); 
     339                                if ($show_post_count) 
    343340                    $after = ' ('.$arcresult->posts.')' . $afterafter; 
    344                 } else { 
    345                     $text = sprintf('%d', $arcresult->year); 
    346                 } 
    347341                echo get_archives_link($url, $text, $format, $before, $after); 
    348342            } 
    349343                }                        
    350344        } elseif ( 'daily' == $type ) { 
    351                 $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth` FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); 
     345                $arcresults = $wpdb->get_results("SELECT DISTINCT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date DESC" . $limit); 
    352346                if ( $arcresults ) { 
     347                        $afterafter = $after; 
    353348                        foreach ( $arcresults as $arcresult ) { 
    354349                                $url    = get_day_link($arcresult->year, $arcresult->month, $arcresult->dayofmonth); 
    355350                                $date = sprintf("%d-%02d-%02d 00:00:00", $arcresult->year, $arcresult->month, $arcresult->dayofmonth); 
    356351                                $text = mysql2date($archive_day_date_format, $date); 
     352                                if ($show_post_count) 
     353                                        $after = ' ('.$arcresult->posts.')'.$afterafter; 
    357354                                echo get_archives_link($url, $text, $format, $before, $after); 
    358355                        } 
    359356                } 
    360357        } elseif ( 'weekly' == $type ) { 
    361358                $start_of_week = get_option('start_of_week'); 
    362                 $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" . $limit); 
     359                $arcresults = $wpdb->get_results("SELECT DISTINCT WEEK(post_date, $start_of_week) AS `week`, YEAR(post_date) AS yr, DATE_FORMAT(post_date, '%Y-%m-%d') AS yyyymmdd, count(ID) as posts FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY WEEK(post_date, $start_of_week), YEAR(post_date) ORDER BY post_date DESC" . $limit); 
    363360                $arc_w_last = ''; 
     361                $afterafter = $after; 
    364362                if ( $arcresults ) { 
    365363                                foreach ( $arcresults as $arcresult ) { 
    366364                                        if ( $arcresult->week != $arc_w_last ) { 
     
    371369                                                $arc_week_end = date_i18n($archive_week_end_date_format, $arc_week['end']); 
    372370                                                $url  = sprintf('%s/%s%sm%s%s%sw%s%d', get_option('home'), '', '?', '=', $arc_year, '&', '=', $arcresult->week); 
    373371                                                $text = $arc_week_start . $archive_week_separator . $arc_week_end; 
     372                                                if ($show_post_count) 
     373                                                        $after = ' ('.$arcresult->posts.')'.$afterafter; 
    374374                                                echo get_archives_link($url, $text, $format, $before, $after); 
    375375                                        } 
    376376                                }