Advertisement
Guest User

WP multi select widget

a guest
Dec 14th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.21 KB | None | 0 0
  1.  
  2. <?php
  3. class Category_Tabs_Widget extends WP_Widget {
  4.      
  5.     function __construct() {
  6.      
  7.         parent::__construct(
  8.              
  9.             // base ID of the widget
  10.             'category_tabs_widget',
  11.              
  12.             // name of the widget
  13.             __('Categpry Tabs', 'custom' ),
  14.              
  15.             // widget options
  16.             array (
  17.                 'description' => __( 'Creates tabs based on selected widgets and returns 4 posts.', 'custom' )
  18.             )
  19.              
  20.         );
  21.          
  22.     }
  23.      
  24.     function form( $instance ) {
  25.      
  26.        
  27.          if( $instance )
  28.             $select = $instance['select'];
  29.         else
  30.              $select ='';
  31.  
  32.         // markup for form
  33.  
  34.      ?>
  35.        <p>
  36.         <label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e('Title:', 'thstlang') ?></label>
  37.         <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name('select'); ?>" value="<?php echo $instance['title']; ?>" />
  38.     </p>
  39.  
  40.     <!-- Category Select Menu -->  
  41.     <p>
  42.         <select id="<?php echo $this->get_field_id('select'); ?>" name="<?php echo $this->get_field_name('select'); ?>[]" class="widefat" style="width:100%;" multiple="multiple">
  43.             <?php foreach(get_terms('product_cat','hide_empty=1') as $term) { ?>
  44.                 <option <?php selected( $instance['select'], $term->term_id ); ?> value="<?php echo $term->term_id; ?>"><?php echo $term->name; ?></option>
  45.             <?php } ?>      
  46.         </select>
  47.     </p>
  48.                  
  49.    <?php
  50.     }
  51.  
  52.  
  53.     function update( $new_instance, $old_instance ) {
  54.      
  55.        $instance = $old_instance;
  56.         $instance['select'] = esc_sql( $new_instance['select'] );
  57.         return $instance;
  58.  
  59.          
  60.     }
  61.      
  62.     function widget( $args, $instance ) {
  63.          
  64.         // kick things off
  65.         extract( $args );
  66.         echo $before_widget;
  67.  
  68.         print_r();      
  69.      //   echo $before_title . 'In this section:' . $after_title;    
  70.          
  71.         // run a query if on a page
  72.        
  73.      
  74.          
  75.    
  76.     ?>
  77.              
  78.         <div class="wpb_tabs wpb_content_element" data-interval="0">
  79.                 <div class="wpb_wrapper wpb_tour_tabs_wrapper ui-tabs vc_clearfix ui-widget ui-widget-content ui-corner-all">
  80.                     <ul class="wpb_tabs_nav ui-tabs-nav vc_clearfix ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" role="tablist"><li class="ui-state-default ui-corner-top" role="tab" tabindex="-1" aria-controls="tab-1407172281-1-37" aria-labelledby="ui-id-1" aria-selected="false" aria-expanded="false"><a href="#tab-1407172281-1-37" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-1">Tab 1</a></li><li class="ui-state-default ui-corner-top" role="tab" tabindex="-1" aria-controls="tab-1407172423209-2-9" aria-labelledby="ui-id-2" aria-selected="false" aria-expanded="false"><a href="#tab-1407172423209-2-9" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-2">Tab 2</a></li><li class="ui-state-default ui-corner-top ui-tabs-active ui-state-active" role="tab" tabindex="0" aria-controls="tab-1407172430389-2-4" aria-labelledby="ui-id-3" aria-selected="true" aria-expanded="true"><a href="#tab-1407172430389-2-4" class="ui-tabs-anchor" role="presentation" tabindex="-1" id="ui-id-3">Tab 3</a></li></ul>
  81.                         <div id="tab-1407172281-1-37" class="wpb_tab ui-tabs-panel wpb_ui-tabs-hide vc_clearfix ui-widget-content ui-corner-bottom" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="true" style="display: none;">
  82.                            
  83.                         <div class="wpb_text_column wpb_content_element ">
  84.                             <div class="wpb_wrapper">
  85.                                 <p>Lorem ipsum pharetra lorem felis. Aliquam egestas consectetur elementum class aptentea taciti sociosqu ad litora torquent perea conubia nostra lorem consectetur adipiscing elit. Donec vestibulum justo a diam ultricies pellentesque.</p>
  86.  
  87.                             </div>
  88.                         </div>
  89.  
  90.                         </div>
  91.                 </div>
  92.             </div>
  93.  
  94.  
  95. <?php
  96.  
  97. echo $after_widget;
  98.  }
  99. }
  100. ?>
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109. <?php
  110. function category_tabs_widget_regiseter() {
  111.  
  112.     register_widget( 'Category_Tabs_Widget' );
  113.  
  114. }
  115. add_action( 'widgets_init', 'category_tabs_widget_regiseter' );
  116. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement