Changeset 28379
- Timestamp:
- 05/13/2014 04:28:56 AM (7 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/general-template.php
r28326 r28379 1174 1174 * @return string|null String when retrieving, null when displaying. 1175 1175 */ 1176 function wp_get_archives( $args = '') {1176 function wp_get_archives( $args = '' ) { 1177 1177 global $wpdb, $wp_locale; 1178 1178 … … 1185 1185 1186 1186 $r = wp_parse_args( $args, $defaults ); 1187 extract( $r, EXTR_SKIP ); 1188 1189 if ( '' == $type )1190 $type = 'monthly';1191 1192 if ( '' != $ limit) {1193 $ limit = absint($limit);1194 $ limit = ' LIMIT '.$limit;1195 } 1196 1197 $order = strtoupper( $ order);1198 if ( $order !== 'ASC' ) 1187 1188 if ( '' == $r['type'] ) { 1189 $r['type'] = 'monthly'; 1190 } 1191 1192 if ( '' != $r['limit'] ) { 1193 $r['limit'] = absint( $r['limit'] ); 1194 $r['limit'] = ' LIMIT ' . $r['limit']; 1195 } 1196 1197 $order = strtoupper( $r['order'] ); 1198 if ( $order !== 'ASC' ) { 1199 1199 $order = 'DESC'; 1200 } 1200 1201 1201 1202 // this is what will separate dates on weekly archive links … … 1212 1213 $archive_week_end_date_format = 'Y/m/d'; 1213 1214 1214 if ( ! $archive_date_format_over_ride ) {1215 $archive_day_date_format = get_option( 'date_format');1216 $archive_week_start_date_format = get_option( 'date_format');1217 $archive_week_end_date_format = get_option( 'date_format');1215 if ( ! $archive_date_format_over_ride ) { 1216 $archive_day_date_format = get_option( 'date_format' ); 1217 $archive_week_start_date_format = get_option( 'date_format' ); 1218 $archive_week_end_date_format = get_option( 'date_format' ); 1218 1219 } 1219 1220 … … 1246 1247 } 1247 1248 1248 if ( 'monthly' == $type ) { 1249 $limit = $r['limit']; 1250 1251 if ( 'monthly' == $r['type'] ) { 1249 1252 $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"; 1250 1253 $key = md5( $query ); … … 1255 1258 } 1256 1259 if ( $results ) { 1257 $after after = $after;1260 $after = $r['after']; 1258 1261 foreach ( (array) $results as $result ) { 1259 1262 $url = get_month_link( $result->year, $result->month ); 1260 1263 /* translators: 1: month name, 2: 4-digit year */ 1261 $text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($result->month), $result->year); 1262 if ( $show_post_count ) 1263 $after = ' ('.$result->posts.')' . $afterafter; 1264 $output .= get_archives_link($url, $text, $format, $before, $after); 1264 $text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year ); 1265 if ( $r['show_post_count'] ) { 1266 $after = ' ('.$result->posts.')' . $after; 1267 } 1268 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $after ); 1265 1269 } 1266 1270 } 1267 } elseif ( 'yearly' == $type) {1271 } elseif ( 'yearly' == $r['type'] ) { 1268 1272 $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"; 1269 1273 $key = md5( $query ); … … 1274 1278 } 1275 1279 if ( $results ) { 1276 $after after = $after;1280 $after = $r['after']; 1277 1281 foreach ( (array) $results as $result) { 1278 $url = get_year_link($result->year); 1279 $text = sprintf('%d', $result->year); 1280 if ($show_post_count) 1281 $after = ' ('.$result->posts.')' . $afterafter; 1282 $output .= get_archives_link($url, $text, $format, $before, $after); 1282 $url = get_year_link( $result->year ); 1283 $text = sprintf( '%d', $result->year ); 1284 if ( $r['show_post_count'] ) { 1285 $r['after'] = ' ('.$result->posts.')' . $after; 1286 } 1287 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1283 1288 } 1284 1289 } 1285 } elseif ( 'daily' == $ type) {1290 } elseif ( 'daily' == $r['type'] ) { 1286 1291 $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"; 1287 1292 $key = md5( $query ); … … 1293 1298 } 1294 1299 if ( $results ) { 1295 $after after = $after;1300 $after = $r['after']; 1296 1301 foreach ( (array) $results as $result ) { 1297 $url = get_day_link($result->year, $result->month, $result->dayofmonth); 1298 $date = sprintf('%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth); 1299 $text = mysql2date($archive_day_date_format, $date); 1300 if ($show_post_count) 1301 $after = ' ('.$result->posts.')'.$afterafter; 1302 $output .= get_archives_link($url, $text, $format, $before, $after); 1302 $url = get_day_link( $result->year, $result->month, $result->dayofmonth ); 1303 $date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth ); 1304 $text = mysql2date( $archive_day_date_format, $date ); 1305 if ( $r['show_post_count'] ) { 1306 $after = ' (' . $result->posts . ')' . $after; 1307 } 1308 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $after ); 1303 1309 } 1304 1310 } 1305 } elseif ( 'weekly' == $ type) {1311 } elseif ( 'weekly' == $r['type'] ) { 1306 1312 $week = _wp_mysql_week( '`post_date`' ); 1307 1313 $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"; … … 1313 1319 } 1314 1320 $arc_w_last = ''; 1315 $after after = $after;1321 $after = $r['after']; 1316 1322 if ( $results ) { 1317 1323 foreach ( (array) $results as $result ) { … … 1319 1325 $arc_year = $result->yr; 1320 1326 $arc_w_last = $result->week; 1321 $arc_week = get_weekstartend( $result->yyyymmdd, get_option('start_of_week'));1322 $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start']);1323 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end']);1324 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week);1327 $arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) ); 1328 $arc_week_start = date_i18n( $archive_week_start_date_format, $arc_week['start'] ); 1329 $arc_week_end = date_i18n( $archive_week_end_date_format, $arc_week['end'] ); 1330 $url = sprintf( '%1$s/%2$s%3$sm%4$s%5$s%6$sw%7$s%8$d', home_url(), '', '?', '=', $arc_year, '&', '=', $result->week ); 1325 1331 $text = $arc_week_start . $archive_week_separator . $arc_week_end; 1326 if ($show_post_count) 1327 $after = ' ('.$result->posts.')'.$afterafter; 1328 $output .= get_archives_link($url, $text, $format, $before, $after); 1332 if ( $r['show_post_count'] ) { 1333 $after = ' (' . $result->posts . ')' . $after; 1334 } 1335 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $after ); 1329 1336 } 1330 1337 } 1331 1338 } 1332 } elseif ( ( 'postbypost' == $ type ) || ('alpha' == $type) ) {1333 $orderby = ( 'alpha' == $type) ? 'post_title ASC ' : 'post_date DESC ';1339 } elseif ( ( 'postbypost' == $r['type'] ) || ('alpha' == $r['type'] ) ) { 1340 $orderby = ( 'alpha' == $r['type'] ) ? 'post_title ASC ' : 'post_date DESC '; 1334 1341 $query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit"; 1335 1342 $key = md5( $query ); … … 1349 1356 $text = $result->ID; 1350 1357 } 1351 $output .= get_archives_link( $url, $text, $format, $before, $after);1358 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1352 1359 } 1353 1360 } 1354 1361 } 1355 1362 } 1356 if ( $ echo )1363 if ( $r['echo'] ) { 1357 1364 echo $output; 1358 else1365 } else { 1359 1366 return $output; 1367 } 1360 1368 } 1361 1369 … … 2510 2518 $r .= "</li>\n</ul>\n"; 2511 2519 break; 2512 2520 2513 2521 default : 2514 2522 $r = join("\n", $page_links);
Note: See TracChangeset
for help on using the changeset viewer.