WordPress.org

Forums

Twenty Twelve
[resolved] Drop down menus for archives and categories (2 posts)

  1. jessica
    Member
    Posted 2 years ago #

    I've been poking around for some time, and maybe these are out of style, but it is what my client wants.

    Is it still possible to create drop down menus for archives and categories in sidebar widgets? I've tried this code without luck, I just get an empty drop down box:

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

    I haven't tried much with the categories drop down yet.

  2. jessica
    Member
    Posted 2 years ago #

    I got this sorted, here's the code I used:

    Browse by month:
    <div id="archive"><select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
      <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
      <?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
    </select></div>
    <br />
    
    Browse by category:
    <div id="cats"><?php wp_dropdown_categories('show_option_none=Select category'); ?>
    
    <script type="text/javascript"><!--
        var dropdown = document.getElementById("cat");
        function onCatChange() {
    		if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    			location.href = "<?php echo get_option('home');
    ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    		}
        }
        dropdown.onchange = onCatChange;
    --></script>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic