iluke
Forum Replies Created
Viewing 2 replies - 1 through 2 (of 2 total)
-
Forum: Fixing WordPress
In reply to: Modify wp_get_archives | highlight current archive categoryAs of 2.7 update, the hack I posted is now around line 626 of the same file:
/** * Retrieve archive link content based on predefined or custom code. * * The format can be one of four styles. The 'link' for head element, 'option' * for use in the select element, 'html' for use in list (either ol or ul HTML * elements). Custom content is also supported using the before and after * parameters. * * The 'link' format uses the link HTML element with the <em>archives</em> * relationship. The before and after parameters are not used. The text * parameter is used to describe the link. * * The 'option' format uses the option HTML element for use in select element. * The value is the url parameter and the before and after parameters are used * between the text description. * * The 'html' format, which is the default, uses the li HTML element for use in * the list HTML elements. The before parameter is before the link and the after * parameter is after the closing link. * * The custom format uses the before parameter before the link ('a' HTML * element) and the after parameter after the closing link tag. If the above * three values for the format are not used, then custom format is assumed. * * @since 1.0.0 * @author Orien * @link https://icecode.com/ link navigation hack by Orien * * @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. * @param string $after Optional. * @return string HTML link content for archive. */ function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { $text = wptexturize($text); $title_text = attribute_escape($text); $url = clean_url($url); // modified 2008-12-15 by luke wertz if ('link' == $format) { $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n"; } elseif ('option' == $format) { $link_html = "\t<option value='$url'>$before $text $after</option>\n"; } elseif ('html' == $format) { $requested = "https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; if ($requested == $url){ $class = " class='current-cat'"; } else { $class = null; } $link_html = "\t<li$class>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n"; } else { // custom $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n"; } $link_html = apply_filters( "get_archives_link", $link_html ); return $link_html; }
Forum: Fixing WordPress
In reply to: Modify wp_get_archives | highlight current archive categoryI was able to hack this up really quickly… be warned, this is mostly untested, but it should do what you want.
Find in /wp-includes/general-template.php line 352. It should be the
get_archives_link
function declaration… replace that function with this modified one:/* link navigation hack by Orien https://icecode.com/ */ function get_archives_link($url, $text, $format = 'html', $before = '', $after = '') { $text = wptexturize($text); $title_text = attribute_escape($text); $url = clean_url($url); if ('link' == $format) { $link_html = "\t<link rel='archives' title='$title_text' href='$url' />\n"; } elseif ('option' == $format) { $link_html = "\t<option value='$url'>$before $text $after</option>\n"; } elseif ('html' == $format) { $requested = "https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"; if ($requested == $url){ $class = " class='current-cat'"; } else { $class = null; } $link_html = "\t<li$class>$before<a href='$url' title='$title_text'>$text</a>$after</li>\n"; } else { // custom $link_html = "\t$before<a href='$url' title='$title_text'>$text</a>$after\n"; } $link_html = apply_filters( "get_archives_link", $link_html ); return $link_html; }
For anyone who cares: all this is doing now is testing for the requested uri and checking it against the returned $url from the original function… it currently applies a class of current-cat to the
<li>
.HTH.
Luke
Viewing 2 replies - 1 through 2 (of 2 total)