Index: src/wp-includes/general-template.php
===================================================================
--- src/wp-includes/general-template.php (revision 44640)
+++ src/wp-includes/general-template.php (working copy)
@@ -1660,21 +1660,23 @@
*
* @since 1.0.0
*
- * @param string $url URL to archive.
- * @param string $text Archive text description.
- * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
- * @param string $before Optional. Content to prepend to the description. Default empty.
- * @param string $after Optional. Content to append to the description. Default empty.
+ * @param string $url URL to archive.
+ * @param string $text Archive text description.
+ * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom.
+ * @param string $before Optional. Content to prepend to the description. Default empty.
+ * @param string $after Optional. Content to append to the description. Default empty.
+ * @param bool $selected Optional. Set to true if the current page is the selected archive page.
* @return string HTML link content for archive.
*/
-function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '' ) {
+function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) {
$text = wptexturize( $text );
$url = esc_url( $url );
if ( 'link' == $format ) {
$link_html = "\t\n";
- } elseif ( 'option' == $format ) {
- $link_html = "\t\n";
+ } elseif ('option' == $format) {
+ $selected_attr = $selected ? " selected='selected'" : '';
+ $link_html = "\t\n";
} elseif ( 'html' == $format ) {
$link_html = "\t
$before$text$after\n";
} else { // custom
@@ -1693,8 +1695,9 @@
* @param string $format Link format. Can be 'link', 'option', 'html', or custom.
* @param string $before Content to prepend to the description.
* @param string $after Content to append to the description.
+ * @param bool $selected True if the current page is the selected archive
*/
- return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );
+ return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected );
}
/**
@@ -1745,6 +1748,10 @@
'echo' => 1,
'order' => 'DESC',
'post_type' => 'post',
+ 'year' => get_query_var( 'year' ),
+ 'monthnum' => get_query_var( 'monthnum' ),
+ 'day' => get_query_var( 'day' ),
+ 'week' => get_query_var( 'w' ),
);
$r = wp_parse_args( $args, $defaults );
@@ -1820,7 +1827,8 @@
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
- $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
+ $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year && ( string ) $r[ 'monthnum' ] === $result->month;
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected );
}
}
} elseif ( 'yearly' == $r['type'] ) {
@@ -1842,7 +1850,8 @@
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
- $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
+ $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year;
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected );
}
}
} elseif ( 'daily' == $r['type'] ) {
@@ -1865,7 +1874,8 @@
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
- $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
+ $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year && ( string ) $r[ 'monthnum' ] === $result->month && ( string ) $r[ 'day' ] === $result->dayofmonth;
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected );
}
}
} elseif ( 'weekly' == $r['type'] ) {
@@ -1901,7 +1911,8 @@
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
- $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
+ $selected = is_archive() && ( string ) $r[ 'year' ] === $result->yr && ( string ) $r[ 'week' ] === $result->week;
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected );
}
}
}
@@ -1924,7 +1935,8 @@
} else {
$text = $result->ID;
}
- $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
+ $selected = $result->ID === get_the_ID();
+ $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected );
}
}
}