Ticket #40662: 40662.3.diff
File 40662.3.diff, 5.1 KB (added by , 6 years ago) |
---|
-
src/wp-includes/general-template.php
1660 1660 * 1661 1661 * @since 1.0.0 1662 1662 * 1663 * @param string $url URL to archive. 1664 * @param string $text Archive text description. 1665 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. 1666 * @param string $before Optional. Content to prepend to the description. Default empty. 1667 * @param string $after Optional. Content to append to the description. Default empty. 1663 * @param string $url URL to archive. 1664 * @param string $text Archive text description. 1665 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. 1666 * @param string $before Optional. Content to prepend to the description. Default empty. 1667 * @param string $after Optional. Content to append to the description. Default empty. 1668 * @param bool $selected Optional. Set to true if the current page is the selected archive page. 1668 1669 * @return string HTML link content for archive. 1669 1670 */ 1670 function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '' ) {1671 function get_archives_link( $url, $text, $format = 'html', $before = '', $after = '', $selected = false ) { 1671 1672 $text = wptexturize( $text ); 1672 1673 $url = esc_url( $url ); 1673 1674 1674 1675 if ( 'link' == $format ) { 1675 1676 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; 1676 } elseif ( 'option' == $format ) { 1677 $link_html = "\t<option value='$url'>$before $text $after</option>\n"; 1677 } elseif ('option' == $format) { 1678 $selected_attr = $selected ? " selected='selected'" : ''; 1679 $link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n"; 1678 1680 } elseif ( 'html' == $format ) { 1679 1681 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n"; 1680 1682 } else { // custom … … 1693 1695 * @param string $format Link format. Can be 'link', 'option', 'html', or custom. 1694 1696 * @param string $before Content to prepend to the description. 1695 1697 * @param string $after Content to append to the description. 1698 * @param bool $selected True if the current page is the selected archive 1696 1699 */ 1697 return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );1700 return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); 1698 1701 } 1699 1702 1700 1703 /** … … 1745 1748 'echo' => 1, 1746 1749 'order' => 'DESC', 1747 1750 'post_type' => 'post', 1751 'year' => get_query_var( 'year' ), 1752 'monthnum' => get_query_var( 'monthnum' ), 1753 'day' => get_query_var( 'day' ), 1754 'week' => get_query_var( 'w' ), 1748 1755 ); 1749 1756 1750 1757 $r = wp_parse_args( $args, $defaults ); … … 1820 1827 if ( $r['show_post_count'] ) { 1821 1828 $r['after'] = ' (' . $result->posts . ')' . $after; 1822 1829 } 1823 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1830 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year && ( string ) $r[ 'monthnum' ] === $result->month; 1831 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1824 1832 } 1825 1833 } 1826 1834 } elseif ( 'yearly' == $r['type'] ) { … … 1842 1850 if ( $r['show_post_count'] ) { 1843 1851 $r['after'] = ' (' . $result->posts . ')' . $after; 1844 1852 } 1845 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1853 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year; 1854 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1846 1855 } 1847 1856 } 1848 1857 } elseif ( 'daily' == $r['type'] ) { … … 1865 1874 if ( $r['show_post_count'] ) { 1866 1875 $r['after'] = ' (' . $result->posts . ')' . $after; 1867 1876 } 1868 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1877 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year && ( string ) $r[ 'monthnum' ] === $result->month && ( string ) $r[ 'day' ] === $result->dayofmonth; 1878 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1869 1879 } 1870 1880 } 1871 1881 } elseif ( 'weekly' == $r['type'] ) { … … 1901 1911 if ( $r['show_post_count'] ) { 1902 1912 $r['after'] = ' (' . $result->posts . ')' . $after; 1903 1913 } 1904 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1914 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->yr && ( string ) $r[ 'week' ] === $result->week; 1915 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1905 1916 } 1906 1917 } 1907 1918 } … … 1924 1935 } else { 1925 1936 $text = $result->ID; 1926 1937 } 1927 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1938 $selected = $result->ID === get_the_ID(); 1939 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1928 1940 } 1929 1941 } 1930 1942 }