If you've been blogging for a while, chances are your list of post archives by month is growing long in the tooth. Thankfully—once you know how—WordPress makes doing something about it pretty easy (a characteristic I've come to appreciate). I had tried to fumble my way to coding a drop-down menu for my archives but my initial efforts were unsuccessful. I then discovered that the solution was right in front of me all along. RTFM.
What are we hoping to achieve?
Let a picture tell the story:

Code replacement
My site is built on the K2 WP modification (r163), which lists archives by month in both page-archives.php and sidebar.php. The original code outputs a simple unordered list (above left) and looks like this:
<div class="sb-months"><h2><?php _e('Archives by month'); ?></h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>
</div>
We can replace it with this (output as above, right):
<div class="sb-months"><h2><?php _e('Archives by month'); ?></h2>
<p>Please select a month:</p>
<noscript><p class="alert">Please enable JavaScript for full functionality</p></noscript>
<select name="archivemenu" onchange="document.location.href=this.options[this.selectedIndex].value;">
<?php get_archives('monthly', '', 'option', '', '', 'TRUE'); ?>
</select>
</div>
This solution does require JavaScript to be enabled and is modified from the example given in the WP Codex here (the code as listed currently is invalid XHTML and generates a PHP parsing error). It is valid XHTML and works with Safari, Firefox, and IE 6 and 7.









Nice, very nice, no need for a plugin or anything. Thanks for the code, I am using it on my archives page also. Keep up the good work. :)
All you need now Wayne is a long list of archives to show it off ;-)
The code isn't mine; as I said it's originally from the Codex—I just modified it to make it valid XHTML (and to work!).
Dear Bruce,
hot to get the same thing listing Categories ?
Thanks
Gigi
Gigi, try wp_list_categories() using the parameters listed here. If you're not using WP 2.1+, search the Codex for the older function.
Bruce,
i'm using this, but it shows only an empty menu:
Please select a category:
Please enable JavaScript for full functionality
Where is the problem ?
Gigi
Sorry Gigi I'm not running WP 2.1 so can't test this. I tried the depreciated functions but couldn't get it working. I suggest trying the WP forums; looks like this question has been asked there recently (but not solved as yet).
Thanks.
Did you notice how these two site achieve it ?
http://www.nomad4ever.com/
http://www.gobackpacking.com/Blog
Gigi you can't see what PHP functions are being called by viewing the page source. Perhaps try asking the webmaster?