Over the past couple years I’ve really enjoyed monitoring trends in the blogosphere and one of the trends that has come up recently is blogger’s cleaning up their sidebars by adding drop-down boxes.

If you’d like to build drop-down boxes for your categories and archives on your WordPress blog, here is the code you need:

Archives Drop-down Code

<select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=\"\"><?php echo attribute_escape(__('Select Month')); ?></option>
<?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>

Categories Drop-down Code

<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?>
<noscript><input type="submit" value="View" /></noscript>
</form>

I think something like this can be a good idea if done with the right theme, but I have also seen it on a few sites where it didn’t look very good, so keep that in mind if you decide to move your categories and archives to a drop-down box!

To see other code snippets we’ve featured here over the past year, check out our WordPress Code page!

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!
Tweet This | | Digg This | Stumble it | | Print This |

Kyle Eslick is WordPress enthusiast who took his passion for WordPress to the next level back in 2007 by launching WPHacks.com as a place to share hacks and review WordPress-related products.

There Are 2 Responses So Far »

  1. Do you have an example of the final result? Thanks for sharing!

  2. Danny says:

    I actually prefer it the old fashioned way, but that’s just me :) good tutorial btw

Trackbacks/Pingbacks »

Leave a Reply