Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** COMIENZO BUSCADOR REGION */
- class JobmanRegionWidget extends WP_Widget {
- /** constructor */
- function JobmanRegionWidget() {
- $name = __( 'Job Manager: Categories', 'jobman');
- $options = array( 'description' => __( 'A list or dropdown of Job Manager categories', 'jobman' ) );
- parent::WP_Widget( false, $name, $options );
- }
- function widget( $args, $instance ) {
- global $wp_query;
- extract( $args );
- $title = apply_filters( 'widget_title', $instance['title'] );
- echo $before_widget;
- if ( $title )
- echo $before_title . $title . $after_title;
- $dropdown = 0;
- if( array_key_exists( 'dropdown', $instance ) )
- $dropdown = $instance['dropdown'];
- $show_counts = 0;
- if( array_key_exists( 'show_counts', $instance ) )
- $show_counts = $instance['show_counts'];
- $hide_empty = 0;
- if( array_key_exists( 'hide_empty', $instance ) )
- $hide_empty = $instance['hide_empty'];
- $categories = get_terms( 'jobman_category', 'hide_empty=0' );
- if( count( $categories ) > 0 ) {
- if( $dropdown ) {
- echo '<select id="jobman-catlist">';
- echo '<option value="">' . __( 'Busqueda por Region', 'jobman' ) . '</option>';
- }
- else {
- echo '<ul>';
- }
- $count_args = array(
- 'post_type' => 'jobman_job',
- 'numberposts' => -1,
- 'suppress_filters' => false
- );
- foreach( $categories as $cat ) {
- $selected = '';
- if( array_key_exists( 'jcat', $wp_query->query_vars ) && $wp_query->query_vars['jcat'] == $cat->slug )
- $selected = ' selected="selected"';
- $jobs = array();
- if( $hide_empty || $show_counts ) {
- $count_args['jcat'] = $cat->slug;
- add_filter( 'posts_where', 'jobman_job_live_where' );
- add_filter( 'posts_join', 'jobman_job_live_join' );
- add_filter( 'posts_distinct', 'jobman_job_live_distinct' );
- $jobs = get_posts( $count_args );
- remove_filter( 'posts_where', 'jobman_job_live_where' );
- remove_filter( 'posts_join', 'jobman_job_live_join' );
- remove_filter( 'posts_distinct', 'jobman_job_live_distinct' );
- }
- if( $hide_empty && empty( $jobs ) )
- continue;
- $count = '';
- if( $show_counts ) {
- $count = ' (' . count( $jobs ) . ')';
- }
- if( $dropdown )
- echo "<option value='$cat->slug'$selected>$cat->name$count</option>";
- else
- echo "<li><a href='" . get_term_link( $cat->slug, 'jobman_category' ) . "'>$cat->name$count</a></li>";
- }
- if( $dropdown ) {
- ?>
- </select>
- <script type='text/javascript'>
- /* <![CDATA[ */
- var jobman_dropdown = document.getElementById("jobman-catlist");
- function onJobmanCatChange() {
- if ( jobman_dropdown.options[jobman_dropdown.selectedIndex].value != '' ) {
- location.href = "<?php echo get_option( 'home' ) ?>/?jcat="+jobman_dropdown.options[jobman_dropdown.selectedIndex].value;
- }
- }
- jobman_dropdown.onchange = onJobmanCatChange;
- /* ]]> */
- </script>
- <?php
- }
- else {
- echo '</ul>';
- }
- }
- else {
- echo '<p>' . __( 'There are no categories to display at this time.', 'jobman' ) . '</p>';
- }
- echo $after_widget;
- }
- function update( $new_instance, $old_instance ) {
- return $new_instance;
- }
- function form( $instance ) {
- $title = '';
- if( array_key_exists( 'title', $instance ) )
- $title = esc_attr( $instance['title'] );
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'jobman' ); ?>:
- <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
- </label>
- </p>
- <?php
- $dropdown = 0;
- if( array_key_exists( 'dropdown', $instance ) )
- $dropdown = $instance['dropdown'];
- $show_counts = 0;
- if( array_key_exists( 'show_counts', $instance ) )
- $show_counts = $instance['show_counts'];
- $hide_empty = 0;
- if( array_key_exists( 'hide_empty', $instance ) )
- $hide_empty = $instance['hide_empty'];
- ?>
- <p>
- <input id="<?php echo $this->get_field_id( 'dropdown' ); ?>" name="<?php echo $this->get_field_name( 'dropdown' ); ?>" type="checkbox" value="1" <?php echo ( $dropdown )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Show as dropdown', 'jobman' ) ?><br/>
- <input id="<?php echo $this->get_field_id( 'show_counts' ); ?>" name="<?php echo $this->get_field_name( 'show_counts' ); ?>" type="checkbox" value="1" <?php echo ( $show_counts )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Show job counts', 'jobman' ); ?><br/>
- <input id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" type="checkbox" value="1" <?php echo ( $hide_empty )?( 'checked="checked" ' ):( '' )?>/> <?php _e( 'Hide empty categories', 'jobman' ); ?>
- </p>
- <?php
- }
- }
- /** FIN REGION */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement