Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Fl0 - http://www.bitpxl.com
- // BUILD THE PLACES WIDGET
- // Multiples instances sort by Checkin & Reviews & News
- // Instructions : http://imath.owni.fr/2012/12/02/bp-checkins-1-1/
- class wdt_sorting_places extends WP_Widget {
- function wdt_sorting_places() {
- // widget settings
- $widget_ops = array( 'classname' => 'Places BY', 'description' => 'Displays places by checkins, reviews or lastest.' );
- // create the widget
- $this->WP_Widget( 'wdt_sorting_places', 'Places BY', $widget_ops );
- }
- function widget( $args, $instance ) {
- extract( $args );
- /* User-selected settings. */
- $title = $instance['title'];
- $sort = $instance['sort'];
- $showplaces = $instance['showplaces'];
- $numplaces = $instance['numplaces'];
- $catplaces = $instance['catplaces'];
- if($sort=="most-check") {
- $feedsort="meta_value";
- $metakey="bpci_place_checked_count";
- } elseif($sort=="most-review") {
- $feedsort="comment_count";
- $metakey="";
- } else {
- $feedsort="date";
- $metakey="";
- }
- /* HTML output */
- ?>
- <?php if($title) { ?><h3><?php echo $title; ?></h3><?php } ?>
- <?php if($showplaces) { ?>
- <ul>
- <?php // setup the query
- $args2 = array(
- 'suppress_filter' => true,
- 'post_type' => 'places',
- 'posts_per_page' => $numplaces,
- 'orderby' => $feedsort,
- 'meta_key' => $metakey
- );
- if($catplaces){
- $args2['tax_query'] = array(
- array(
- 'taxonomy' => 'places_category',
- 'field' => 'slug',
- 'terms' => $catplaces
- )
- );
- }
- $cust_loop = new WP_Query($args2);
- if ($cust_loop->have_posts()) : while ($cust_loop->have_posts()) : $cust_loop->the_post(); $postcount++; ?>
- <li style="list-style:decimal;">
- <?php // bp_checkins_places_featured_image();?>
- <div class="item-title">
- <a class="post-title" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
- </div>
- </li>
- <?php endwhile;
- endif;
- wp_reset_query(); ?>
- </ul>
- <?php } ?>
- <?php
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $title = $instance['title'];
- $sort = $instance['sort'];
- $showplaces = $instance['showplaces'];
- $numplaces = $instance['numplaces'];
- $catplaces = $instance['catplaces'];
- $instance['title'] = strip_tags ( $new_instance['title'] );
- $instance['sort'] = strip_tags( $new_instance['sort'] );
- $instance['showplaces'] = isset( $new_instance['showplaces'] );
- $instance['numplaces'] = strip_tags( $new_instance['numplaces'] );
- $instance['catplaces'] = strip_tags ( $new_instance['catplaces'] );
- return $instance;
- }
- function form( $instance ) {
- /* Set up some default widget settings. */
- $defaults = array( 'title' => 'Places', 'sort' => 'latest', 'showplaces' => true, 'numplaces' => 5 );
- $instance = wp_parse_args( (array) $instance, $defaults ); ?>
- <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>
- <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>
- <p>
- <input class="radio" type="radio" <?php if($instance['sort']=='most-check') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-check" />
- Order places by checkin<br />
- <input class="radio" type="radio" <?php if($instance['sort']=='most-review') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-review" />
- Order places by reviews<br />
- <input class="radio" type="radio" <?php if($instance['sort']=='most-new') { ?>checked <?php } ?>name="<?php echo $this->get_field_name( 'sort' ); ?>" value="most-new" />
- Order places by latest
- </p>
- <p>
- <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' ); ?>" />
- Display
- <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" />
- places
- </p>
- <?php
- }
- }
- //LOAD THE WIDGET
- add_action("widgets_init", "fl0_places_widgets");
- function fl0_places_widgets()
- {
- register_widget('wdt_sorting_places');
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement