Advertisement
Guest User

Untitled

a guest
Oct 26th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.29 KB | None | 0 0
  1. <?php
  2.  
  3. /********* Starting Skill_Level Widget for Sidebar *********/
  4.  
  5. class Skill_Level_Widget extends WP_Widget {
  6.  
  7.     function Skill_Level_Widget(){
  8.         $widget_ops = array( 'classname' => 'Skill_Level_Widget', 'description' => __('Show List of Skill Level.', 'woothemes'));
  9.         $this->WP_Widget( 'skill_level', __('Food & Cook: Skill Level', 'woothemes'), $widget_ops );
  10.     }
  11.  
  12. /********* Starting Skill_Level Widget Function *********/
  13.  
  14.     function widget($args,  $instance) {
  15.         extract($args);
  16.  
  17.         $option = '';
  18.         $title  = apply_filters('widget_title', $instance['title']);
  19.         $view   = apply_filters('skill_level_dropdown', $instance['view']);
  20.  
  21.         if ( empty($title) ) { $title = false; }
  22.  
  23.         if ($view != '' ) {
  24.             $args = array(
  25.                 'hide_empty'         => 1,
  26.                 'taxonomy'           => 'skill_level',
  27.                 'orderby'            => 'slug'
  28.             );
  29.         } else {
  30.             $args = array(
  31.                 'taxonomy'          => 'skill_level',
  32.                 'title_li'          => '',
  33.                 'orderby'            => 'slug'
  34.             );
  35.         }
  36.  
  37.         echo $before_widget;
  38.  
  39.         if($title) {
  40.  
  41.             $temp_title     = explode(' ',$title);
  42.             $first_letter   = $temp_title[0];
  43.  
  44.             unset($temp_title[0]);
  45.  
  46.             $title_new      = implode(' ', $temp_title);
  47.             $title          = $first_letter.' '.$title_new.' ';
  48.  
  49.  
  50.             echo '<h3>'.$title.'</h3>';
  51.  
  52.         }
  53.  
  54.         if ($view != '' ) {
  55.             echo '<select name="sl-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">';
  56.             echo '<option value="">' .esc_attr(__('All Skill Level', 'woothemes')). '</option>';
  57.  
  58.             $categories = get_categories( $args );
  59.             foreach ($categories as $category) {
  60.                 $option .= '<option value="'.esc_url( home_url() ).'/?skill_level='.$category->slug.'">';
  61.                 $option .= $category->cat_name;
  62.                 $option .= ' ('.$category->category_count.')';
  63.                 $option .= '</option>';
  64.             }
  65.             echo $option;
  66.             echo '</select>';
  67.         } else {
  68.             echo '<ul>';
  69.                 wp_list_categories( $args );
  70.             echo '</ul>';
  71.         }
  72.  
  73.         echo $after_widget;
  74.     }
  75.  
  76.  
  77. /********* Starting Skill_Level Widget Admin Form *********/
  78.  
  79.     function form($instance) {
  80.         $instance   = wp_parse_args( (array) $instance, array( 'title' => 'Skill Level' ) );
  81.         $title      = esc_attr($instance['title']);
  82.         $view       = isset($instance['view']) ? (bool) $instance['view'] : true;
  83.  
  84.         ?>
  85.             <p>
  86.                 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title', 'woothemes'); ?></label>
  87.                 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
  88.             </p>
  89.             <p>
  90.                 <input class="checkbox" type="checkbox" <?php checked($view); ?> id="<?php echo $this->get_field_id('view'); ?>" name="<?php echo $this->get_field_name('view'); ?>" />
  91.                 <label for="<?php echo $this->get_field_id('view'); ?>"><?php _e('Display as dropdown ?', 'dahztheme'); ?></label>
  92.             </p>
  93.         <?php
  94.     }
  95.  
  96. /********* Starting Skill_Level Widget Update Function *********/
  97.  
  98.     function update($new_instance, $old_instance) {
  99.         $instance           = $old_instance;
  100.         $instance['title']  = strip_tags($new_instance['title']);
  101.         $instance['view']   = strip_tags($new_instance['view']);
  102.  
  103.         return $instance;
  104.  
  105.     }
  106.  
  107. }
  108. register_widget( 'Skill_Level_Widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement