Forum Moderators: open
I call wp_get_archives in a sidebar, using the defaults so it displays archives listed by month. I want to highlight the month in the list when you are on that month's archive page.
This would be similar to the logic with wp_list_categories when the category list is generated on a Category Archive page, and how the list item for that category is marked with the HTML class current-cat.
I know the XHTML/CSS involved (i.e., I know how to style the markup to get that affect) - but I CANNOT figure out how to coerce WordPress to generate the necessary class attribute for me to use as a style hook.
I need something like this:
<ul id="archives">
<li class="selected"><a href="#" title="April 2008">April 2008</a></li>
<li><a href="#" title="March 2008">March 2008</a></li>
<li><a href="#" title="Feb 2008">Feb 2008</a></li>
...
</ul>
How do I get wp_get_archives to generate a class attribute for the selected archive month?
Like I say, I'm sure it can be done with a plugin, I just don't know how.
If you want to live dangerously and hack the Wordpress code (and then invite upgrade hell), basically you would need to get into the wp_get_archives() function in the general-template.php file.
instead of line 417 (2.5.1)
echo get_archives_link($url, $text, $format, $before, $after);
you would want something like (this is untested)
if ($url == $_SERVER['REQUEST_URI'])
{
$before = $before . '<span class="current">';
$after = '</span>' . $after;
}
echo get_archives_link($url, $text, $format, $before, $after);
That's just off the top of my head - I'm not sure what format the $url variable has, so you would have to output it and see if you need to do some additional processing before comparing it to $_SERVER['REQUEST_URI']
I don't know if that helps. If you can find someone who really knows the plugin API, I'm sure they could do it smarter.
As for the general idea of hacking WP's core files, I've been doing that a bit already. I try to keep track for future updates, but its living dangerously, for sure :) Sometimes there doesn't seem to be other options.
This particular issue, though, has really had me scratching my head. I understand the logic behind your suggestion (I'm not a php expert), so I'll see what I can do with it - and update back here on the results.