WordPress.org

Support

Support » Themes and Templates » Adding "selected" attribute to current item in archive dropdown

Adding "selected" attribute to current item in archive dropdown

  • Hello!

    I’ve got a wp_get_archives script all set up that provides a drop down just the way I want it.

    However, I’d like to make it just a little bit more perfected and add the “selected” attribute to the option of the current post so that the current post name is displayed when the drop down is not extended.

    Here’s my code:

    <select name=\"archive-dropdown\" onChange='document.location.href=this.options[this.selectedIndex].value;'>
            <?php wp_get_archives('type=postbypost&format=option&show_post_count=0'); ?>
    </select>

    Also, something I noticed was that all the posts in the drop down are displaying in reverse order. I have a post query reversing the order of posts on the page. I tried to counteract this in the wp_get_archives with an “order” argument, but it didn’t have any effect.

    Thanks!

  • The topic ‘Adding "selected" attribute to current item in archive dropdown’ is closed to new replies.