Advertisement
Guest User

Bp-checkins widget by @Fl0

a guest
Dec 4th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.92 KB | None | 0 0
  1. <?php
  2. // Fl0 - http://www.bitpxl.com
  3. // BUILD THE PLACES WIDGET
  4. // Multiples instances sort by Checkin & Reviews & News
  5. // Instructions : http://imath.owni.fr/2012/12/02/bp-checkins-1-1/
  6.  
  7. class wdt_sorting_places extends WP_Widget {
  8.     function wdt_sorting_places() {
  9.         // widget settings
  10.         $widget_ops = array( 'classname' => 'Places BY', 'description' => 'Displays places by checkins, reviews or lastest.' );
  11.         // create the widget
  12.         $this->WP_Widget( 'wdt_sorting_places', 'Places BY', $widget_ops );
  13.     }
  14.     function widget( $args, $instance ) {
  15.         extract( $args );
  16.         /* User-selected settings. */
  17.         $title = $instance['title'];
  18.         $sort = $instance['sort'];
  19.         $showplaces = $instance['showplaces'];
  20.         $numplaces = $instance['numplaces'];
  21.         $catplaces = $instance['catplaces'];
  22.         if($sort=="most-check") {
  23.             $feedsort="meta_value";
  24.             $metakey="bpci_place_checked_count";
  25.         } elseif($sort=="most-review") {
  26.             $feedsort="comment_count";
  27.             $metakey="";
  28.         } else {
  29.             $feedsort="date";
  30.             $metakey="";
  31.         }
  32.         /* HTML output */
  33.         ?>
  34.    
  35.             <?php if($title) { ?><h3><?php echo $title; ?></h3><?php } ?>
  36.            
  37.                 <?php if($showplaces) { ?>
  38.                    
  39.                         <ul>
  40.                             <?php // setup the query
  41.                            
  42.                             $args2 = array(
  43.                             'suppress_filter'    => true,
  44.                             'post_type'  => 'places',
  45.                             'posts_per_page' => $numplaces,
  46.                             'orderby'   => $feedsort,
  47.                             'meta_key' => $metakey
  48.                             );
  49.                            
  50.                             if($catplaces){
  51.                             $args2['tax_query'] = array(
  52.                                                     array(
  53.                                                         'taxonomy' => 'places_category',
  54.                                                         'field' => 'slug',
  55.                                                         'terms' => $catplaces
  56.                                                         )
  57.                                                 );
  58.                             }
  59.                            
  60.                             $cust_loop = new WP_Query($args2);
  61.                             if ($cust_loop->have_posts()) : while ($cust_loop->have_posts()) : $cust_loop->the_post(); $postcount++;    ?>
  62.                             <li style="list-style:decimal;">
  63.                             <?php // bp_checkins_places_featured_image();?>
  64.                             <div class="item-title">
  65.                             <a class="post-title" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
  66.                             </div>
  67.                             </li>
  68.                             <?php endwhile;
  69.                             endif;
  70.                             wp_reset_query(); ?>
  71.                         </ul>
  72.                    
  73.             <?php } ?>
  74.     <?php
  75.     }
  76.     function update( $new_instance, $old_instance ) {
  77.         $instance = $old_instance;
  78.         $title = $instance['title'];
  79.         $sort = $instance['sort'];
  80.         $showplaces = $instance['showplaces'];
  81.         $numplaces = $instance['numplaces'];
  82.         $catplaces = $instance['catplaces'];
  83.         $instance['title'] = strip_tags ( $new_instance['title'] );
  84.         $instance['sort'] = strip_tags( $new_instance['sort'] );
  85.         $instance['showplaces'] = isset( $new_instance['showplaces'] );
  86.         $instance['numplaces'] = strip_tags( $new_instance['numplaces'] );
  87.         $instance['catplaces'] = strip_tags ( $new_instance['catplaces'] );
  88.         return $instance;
  89.     }
  90.     function form( $instance ) {
  91.         /* Set up some default widget settings. */
  92.         $defaults = array( 'title' => 'Places', 'sort' => 'latest', 'showplaces' => true, 'numplaces' => 5 );
  93.         $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  94.         <p><label for="wdt-places-title">Title <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" style="width: 100%" /></label></p>
  95.        
  96.         <p><label for="wdt-places-cat">Category <input class="widefat" id="<?php echo $this->get_field_id( 'catplaces' ); ?>" name="<?php echo $this->get_field_name( 'catplaces' ); ?>" type="text" value="<?php echo $instance['catplaces']; ?>" style="width: 100%" /></label></p>
  97.        
  98.         <p>
  99.             <input class="radio" type="radio" <?php if($instance['sort']=='most-check') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-check" />
  100.             Order places by checkin<br />
  101.             <input class="radio" type="radio" <?php if($instance['sort']=='most-review') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-review" />
  102.             Order places by reviews<br />
  103.             <input class="radio" type="radio" <?php if($instance['sort']=='most-new') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-new" />
  104.             Order places by latest
  105.         </p>
  106.         <p>
  107.             <input class="checkbox" type="checkbox" <?php checked(isset( $instance['showplaces']) ? $instance['showplaces'] : 0  ); ?> id="<?php echo $this->get_field_id( 'showplaces' ); ?>" name="<?php echo $this->get_field_name( 'showplaces' ); ?>" />
  108.             Display
  109.             <input id="<?php echo $this->get_field_id( 'numplaces' ); ?>" name="<?php echo $this->get_field_name( 'numplaces' ); ?>" value="<?php echo $instance['numplaces']; ?>" style="width:30px" />
  110.             places
  111.         </p>
  112.         <?php
  113.     }
  114. }
  115. //LOAD THE WIDGET
  116. add_action("widgets_init", "fl0_places_widgets");
  117. function fl0_places_widgets()
  118. {
  119.     register_widget('wdt_sorting_places');
  120. }
  121. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement