示例#1
0
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args Widget arguments.
  * @param array $instance Saved values from database.
  */
 public function widget($args, $instance)
 {
     // Disable the widget if we're already on the search results page
     if (get_the_ID() == wpus_option('results_page')) {
         return;
     }
     extract($args);
     $title = apply_filters('widget_title', $instance['title']);
     echo $before_widget;
     if (!empty($title)) {
         echo $before_title . $title . $after_title;
     }
     $atts = array('widget' => true);
     wp_ultimate_search_bar($atts);
     echo $after_widget;
 }
    ?>

	<?php 
    if (wpus_option('clear_search')) {
        ?>
		<a id="wpus-clear-search" class="<?php 
        echo wpus_option('clear_search_class');
        ?>
" href="#"><?php 
        echo wpus_option('clear_search_text');
        ?>
</a>
	<?php 
    }
    ?>

	<?php 
    wp_reset_postdata();
    ?>

<?php 
} else {
    ?>

	<div class="wpus-no-results"><?php 
    echo wpus_option('no_results_msg');
    ?>
</div>

<?php 
}
 /**
  * register_scripts
  *
  */
 public function register_scripts()
 {
     // ENQUEUE VISUALSEARCH SCRIPTS
     wp_enqueue_script('underscore');
     wp_enqueue_script('backbone');
     wp_enqueue_script('visualsearch', WPUS_DIR_URL . 'js/visualsearch.min.js', array('jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-position', 'jquery-ui-autocomplete', 'backbone', 'underscore'));
     $options = $this->options;
     if (isset($options['radius']) && $options['radius'] != FALSE) {
         $radius = $options['radius'];
     } else {
         $radius = FALSE;
     }
     // ENQUEUE AND LOCALIZE MAIN JS FILE
     wp_enqueue_script('wpus-script', WPUS_DIR_URL . 'js/main-pro.js', array('visualsearch'), '', wpus_option('scripts_in_footer'));
     if ($radius) {
         wp_enqueue_script('google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places');
         wp_enqueue_script('geocomplete', WPUS_DIR_URL . 'js/jquery.geocomplete.js', array('jquery', 'google-maps'), '', wpus_option('scripts_in_footer'));
     }
     $options['show_facets'] == 1 ? $showfacets = TRUE : ($showfacets = FALSE);
     $options['highlight_terms'] == 1 ? $highlight = TRUE : ($highlight = FALSE);
     $params = array('ajaxurl' => admin_url('admin-ajax.php'), 'searchNonce' => wp_create_nonce('search-nonce'), 'trackevents' => $options['track_events'], 'eventtitle' => $options['event_category'], 'enabledfacets' => json_encode($this->get_enabled_facets()), 'resultspage' => get_permalink($options['results_page']), 'showfacets' => $showfacets, 'placeholder' => $options['placeholder'], 'highlight' => $highlight, 'radius' => $radius, 'remainder' => $options['remainder'], 'single_facet' => $options['single_facet_mode'], 'disable_permalinks' => $options['disable_permalinks'], 'single_use' => $options['single_use']);
     wp_localize_script('wpus-script', 'wpus_script', $params);
     // ENQUEUE STYLES
     if (isset($options['style'])) {
         if ($options['style'] == 'square') {
             wp_enqueue_style('wpus-bar', WPUS_DIR_URL . 'css/square.css');
         } else {
             wp_enqueue_style('wpus-bar', WPUS_DIR_URL . 'css/visualsearch.css');
         }
     } else {
         wp_enqueue_style('wpus-bar', WPUS_DIR_URL . 'css/visualsearch.css');
     }
 }