Ticket #40662: 40662.diff
File 40662.diff, 5.2 KB (added by , 8 years ago) |
---|
-
wp-includes/general-template.php
1604 1604 * 1605 1605 * @since 1.0.0 1606 1606 * 1607 * @param string $url URL to archive. 1608 * @param string $text Archive text description. 1609 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. 1610 * @param string $before Optional. Content to prepend to the description. Default empty. 1611 * @param string $after Optional. Content to append to the description. Default empty. 1607 * @param string $url URL to archive. 1608 * @param string $text Archive text description. 1609 * @param string $format Optional, default is 'html'. Can be 'link', 'option', 'html', or custom. 1610 * @param string $before Optional. Content to prepend to the description. Default empty. 1611 * @param string $after Optional. Content to append to the description. Default empty. 1612 * @param bool $selected Optional. Set to true if the current page is the selected archive page 1612 1613 * @return string HTML link content for archive. 1613 1614 */ 1614 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '' ) {1615 function get_archives_link($url, $text, $format = 'html', $before = '', $after = '', $selected = false) { 1615 1616 $text = wptexturize($text); 1616 1617 $url = esc_url($url); 1617 1618 1618 1619 if ('link' == $format) 1619 1620 $link_html = "\t<link rel='archives' title='" . esc_attr( $text ) . "' href='$url' />\n"; 1620 elseif ('option' == $format) 1621 $link_html = "\t<option value='$url'>$before $text $after</option>\n"; 1622 elseif ('html' == $format) 1621 elseif ('option' == $format) { 1622 $selected_attr = $selected ? " selected='selected'" : ''; 1623 $link_html = "\t<option value='$url'$selected_attr>$before $text $after</option>\n"; 1624 } elseif ('html' == $format) 1623 1625 $link_html = "\t<li>$before<a href='$url'>$text</a>$after</li>\n"; 1624 1626 else // custom 1625 1627 $link_html = "\t$before<a href='$url'>$text</a>$after\n"; … … 1636 1638 * @param string $format Link format. Can be 'link', 'option', 'html', or custom. 1637 1639 * @param string $before Content to prepend to the description. 1638 1640 * @param string $after Content to append to the description. 1641 * @param bool $selected True if the current page is the selected archive 1639 1642 */ 1640 return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after );1643 return apply_filters( 'get_archives_link', $link_html, $url, $text, $format, $before, $after, $selected ); 1641 1644 } 1642 1645 1643 1646 /** … … 1683 1686 'format' => 'html', 'before' => '', 1684 1687 'after' => '', 'show_post_count' => false, 1685 1688 'echo' => 1, 'order' => 'DESC', 1686 'post_type' => 'post' 1689 'post_type' => 'post', 1690 'year' => get_query_var( 'year' ), 1691 'monthnum' => get_query_var( 'monthnum' ), 1692 'day' => get_query_var( 'day' ), 1693 'week' => get_query_var( 'w' ) 1687 1694 ); 1688 1695 1689 1696 $r = wp_parse_args( $args, $defaults ); … … 1759 1766 if ( $r['show_post_count'] ) { 1760 1767 $r['after'] = ' (' . $result->posts . ')' . $after; 1761 1768 } 1762 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1769 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year 1770 && ( string ) $r[ 'monthnum' ] === $result->month; 1771 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1763 1772 } 1764 1773 } 1765 1774 } elseif ( 'yearly' == $r['type'] ) { … … 1781 1790 if ( $r['show_post_count'] ) { 1782 1791 $r['after'] = ' (' . $result->posts . ')' . $after; 1783 1792 } 1784 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1793 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year; 1794 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1785 1795 } 1786 1796 } 1787 1797 } elseif ( 'daily' == $r['type'] ) { … … 1804 1814 if ( $r['show_post_count'] ) { 1805 1815 $r['after'] = ' (' . $result->posts . ')' . $after; 1806 1816 } 1807 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1817 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->year 1818 && ( string ) $r[ 'monthnum' ] === $result->month 1819 && ( string ) $r[ 'day' ] === $result->dayofmonth; 1820 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1808 1821 } 1809 1822 } 1810 1823 } elseif ( 'weekly' == $r['type'] ) { … … 1834 1847 if ( $r['show_post_count'] ) { 1835 1848 $r['after'] = ' (' . $result->posts . ')' . $after; 1836 1849 } 1837 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1850 $selected = is_archive() && ( string ) $r[ 'year' ] === $result->yr 1851 && ( string ) $r[ 'week' ] === $result->week; 1852 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1838 1853 } 1839 1854 } 1840 1855 } … … 1857 1872 } else { 1858 1873 $text = $result->ID; 1859 1874 } 1860 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] ); 1875 $selected = $result->ID === get_the_ID(); 1876 $output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'], $selected ); 1861 1877 } 1862 1878 } 1863 1879 }