Advertisement
Guest User

Untitled

a guest
Oct 11th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.85 KB | None | 0 0
  1. class blog_arch extends WP_Widget{
  2.     // Initialization
  3.     function blog_arch() {
  4.         $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site’s posts') );
  5.         parent::WP_Widget('archives', __('Archives'), $widget_ops);
  6.     }
  7.  
  8.     function widget( $args, $instance ) {
  9.         extract($args);
  10.         $c = ! empty( $instance['count'] ) ? '1' : '0';
  11.         $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
  12.         $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
  13.  
  14.         echo $before_widget;
  15.         if ( $title )
  16.             echo $before_title . $title . $after_title;
  17.  
  18.         if ( $d ) {
  19. ?>
  20.         <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(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
  21. <?php
  22.         } else {
  23. ?>
  24.         <ul class="archives">
  25.         <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
  26.         </ul>
  27. <?php
  28.         }
  29.  
  30.         echo $after_widget;
  31.     }
  32.  
  33.     function update( $new_instance, $old_instance ) {
  34.         $instance = $old_instance;
  35.         $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  36.         $instance['title'] = strip_tags($new_instance['title']);
  37.         $instance['count'] = $new_instance['count'] ? 1 : 0;
  38.         $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
  39.  
  40.         return $instance;
  41.     }
  42.  
  43.     function form( $instance ) {
  44.         $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  45.         $title = strip_tags($instance['title']);
  46.         $count = $instance['count'] ? 'checked="checked"' : '';
  47.         $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
  48. ?>
  49.         <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
  50.         <p>
  51.             <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
  52.             <br/>
  53.             <input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
  54.         </p>
  55. <?php
  56.     }
  57. }
  58. add_action('widgets_init', create_function('', 'return register_widget("blog_arch");'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement