Advertisement
Guest User

Untitled

a guest
Jan 19th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.44 KB | None | 0 0
  1. <?
  2. // Creating the widget
  3. class delivery_widget extends WP_Widget {
  4.  
  5.     function __construct() {
  6.         parent::__construct(
  7.             'delivery_widget',
  8.             __('Delivery Pesquisa', 'delivery_widget_domain'),
  9.             array( 'description' => __( 'Widget para box de delivery', 'delivery_widget_domain' ), )
  10.         );
  11.     }
  12.  
  13.     // Creating widget front-end
  14.     // This is where the action happens
  15.     public function widget( $args, $instance ) {
  16.         $title = apply_filters( 'widget_title', $instance['title'] );
  17.         $sub_title = apply_filters('widget_title', $instance['sub_title']);
  18.         echo $args['before_widget'];
  19.         if ( ! empty( $title ) ) {
  20.             echo $args['before_title'] . $title;
  21.             if(!empty($sub_title))
  22.                 echo '<span>' . $sub_title . '</span>';
  23.  
  24.              echo $args['after_title'];
  25.         }
  26.  
  27.         echo $this->deliverySearch();
  28.         echo $args['after_widget'];
  29.     }
  30.  
  31.     // Widget Backend
  32.     public function form( $instance ) {
  33.         if ( isset( $instance[ 'title' ] ) ) {
  34.             $title = $instance[ 'title' ];
  35.         } else {
  36.             $title = __( 'Delivery', 'delivery_widget_domain' );
  37.         }
  38.  
  39.         if (isset($instance['sub_title'])){
  40.             $sub_title = $instance['sub_title'];
  41.         } else {
  42.             $sub_title = __('escolha uma categoria', 'delivery_widget_domain');
  43.         }
  44.         // Widget admin form
  45.         ?>
  46.         <p>
  47.             <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  48.             <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 ); ?>" />
  49.         </p>
  50.         <p>
  51.             <label for="<?php echo $this->get_field_id('sub_title'); ?>"><?php _e('Sub Título:'); ?></label>
  52.             <input class="widefat" id="<?php echo $this->get_field_id('sub_title'); ?>" name="<?php echo $this->get_field_name('sub_title'); ?>" type="text" value="<?php echo esc_attr($sub_title); ?>" />
  53.         </p>
  54.       <?php
  55.   }
  56.  
  57.     // Updating widget replacing old instances with new
  58.     public function update( $new_instance, $old_instance ) {
  59.         $instance = array();
  60.         $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
  61.         $instance['sub_title'] = (!empty($new_instance['sub_title'])) ? strip_tags($new_instance['sub_title']): '';
  62.         return $instance;
  63.     }
  64.  
  65.     private function deliverySearch(){
  66.         $html = <<<EOT
  67.         <div class="loading"></div>
  68.         <div class="delivery-widget-slider-wrapper">
  69.             <ul class="slider-delivery-widget">
  70. EOT;
  71.         $html .= $this->printCategorias();
  72.         $html .= "</ul></div>";
  73.         return $html;
  74.     }
  75.  
  76.     private function printCategorias(){
  77.         $terms = get_terms("deliverys","hide_empty=1");
  78.         $count = count($terms);
  79.         $terms = apply_filters( 'taxonomy-images-get-terms', '' , array('taxonomy' => 'deliverys'));
  80.         $html = '';
  81.         if ($count > 0){
  82.             foreach($terms as $term){
  83.                 $imagem = wp_get_attachment_image_src($term->image_id);
  84.                 $imagem = $imagem[0];
  85.                 $link = get_site_url() . "/delivery/?categoria=" . $term->slug;
  86.                 $nome = $term->name;
  87.                 $html .= <<<EOT
  88.                 <li>
  89.                     <a href="$link"><img src="$imagem" /></a>
  90.                     <p>$nome</p>
  91.                 </li>
  92. EOT;
  93.             }
  94.         }
  95.  
  96.         return $html;
  97.  
  98.     }
  99. } // Class delivery_widget ends here
  100.  
  101. // Register and load the widget
  102. function wpb_load_widget() {
  103.     register_widget( 'delivery_widget' );
  104. }
  105. add_action( 'widgets_init', 'wpb_load_widget' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement