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