• Hey Guys,

    I’m trying to convert my list of archived months to a dropdown. I’ve gotten it to work, however not 100% correctly. Can someone please explain this function to me:

    function wp_widget_archives($args) {
    	extract($args);
    	$options = get_option('widget_archives');
    	$c = $options['count'] ? '1' : '0';
    	$d = $options['dropdown'] ? '1' : '0';
    	$title = empty($options['title']) ? __('Archives') : $options['title'];
    
    	echo $before_widget;
    	echo $before_title . $title . $after_title;
    
    	if($d) {
    ?>
    		<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=$c"); ?> </select>
    <?php
    	} else {
    ?>
    		<ul>
    		<?php wp_get_archives("type=monthly&show_post_count=$c"); ?>
    		</ul>
    <?php
    	}
    
    	echo $after_widget;
    }

    All I’ve done is basically replace:

    <?php //wp_get_archives('type=monthly&limit=12&show_post_count=1'); ?>

    with:

    <?php wp_widget_archives('type=monthly&limit=12&show_post_count=1'); ?>

    But that alone isn’t getting it done. Any suggestions would be appreciated.

    Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter kraftomatic

    (@kraftomatic)

    anyone?

    Moderator Samuel Wood (Otto)

    (@otto42)

    ww.wp.xz.cn Admin

    That’s a widget, you would not use a widget directly like that. If your theme uses widgets, go to Presentation->Widgets and just drag and drop the archives widget into place.

    If not, then you need to roll your own code like so:
    <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("format=option&type=monthly&limit=12&show_post_count=1"); ?> </select>

    Thanks a lot for this. It helps a lot! I have been looking for this code all around! I am not keen to use the widget, coz it appears ugly on my theme… 🙂

    Moderator Samuel Wood (Otto)

    (@otto42)

    ww.wp.xz.cn Admin

    Then your theme needs to be adjusted to make widgets work properly.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Converting Archives to a Drop Down Correctly’ is closed to new replies.