Results 1 to 3 of 3

Thread: Job Types widget

  1. #1
    Thread Starter
    Newbie girolamis's Avatar
    Join Date
    Sep 2010
    Location
    United States
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Job Types widget

    How can I make a job types widget for my sidebars similar to the job categories widget?

    I tried copying the JR_Widget_Job_Categories widget code and modifying it for job_types where I thought appropriate, but it didn't exactly work.

    Here is the copy I made:

    Code:
    // the job types sidebar widget
    class JR_Widget_Job_Types extends WP_Widget {
    
        function JR_Widget_Job_Types() {
            $widget_ops = array( 'classname' => 'widget_job_types', 'description' => __( "A list or dropdown of job types", 'jr' ) );
            $this->WP_Widget('job_types', __('Job Types', 'jr'), $widget_ops);
        }
    
        function widget( $args, $instance ) {
            extract( $args );
    
            $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Job Types', 'jr' ) : $instance['title'], $instance, $this->id_base);
            $c = $instance['count'] ? '1' : '0';
            $h = $instance['hierarchical'] ? '1' : '0';
            $d = $instance['dropdown'] ? '1' : '0';
    
            echo $before_widget;
            if ( $title )
                echo $before_title . $title . $after_title;
    
            $type_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'taxonomy' => 'job_type');
    
            if ( $d ) {
                $type_args['show_option_none'] = __('Select Type', 'jr');
                wp_dropdown_types(apply_filters('widget_job_types_dropdown_args', $type_args));
    ?>
    
    <script type='text/javascript'>
    /* <![CDATA[ */
        var dropdown = document.getElementById("type");
        function onTypeChange() {
            if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
                location.href = "<?php echo home_url(); ?>/?type="+dropdown.options[dropdown.selectedIndex].value;
            }
        }
        dropdown.onchange = onTypeChange;
    /* ]]> */
    </script>
    
    <?php
            } else {
    ?>
            <ul>
    <?php
            $type_args['title_li'] = '';
            wp_list_types(apply_filters('widget_job_types_args', $type_args));
    ?>
            </ul>
    <?php
            }
    
            echo $after_widget;
        }
    
        function update( $new_instance, $old_instance ) {
            $instance = $old_instance;
            $instance['title'] = strip_tags($new_instance['title']);
            $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
            $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
            $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
    
            return $instance;
        }
    
        function form( $instance ) {
            //Defaults
            $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
            $title = esc_attr( $instance['title'] );
            $count = isset($instance['count']) ? (bool) $instance['count'] :false;
            $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
            $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
    ?>
            <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
            <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; ?>" /></p>
    
            <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
            <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Show as dropdown' ); ?></label><br />
    
            <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
            <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
    
            <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
            <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
    <?php
        }
    
    }

  2. #2
    Thread Starter
    Newbie girolamis's Avatar
    Join Date
    Sep 2010
    Location
    United States
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!

  3. #3
    jomarkosabel's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    40,958
    Thanks
    169
    Thanked 3,405 Times in 3,276 Posts
    You must be an AppThemes customer and logged in to view this response. Join today!
    Please help our moderating team work more efficiently by not sending us support questions via PM. You can read more about how AppThemes support works here. However, you can send a PM to follow up and remind me if I missed your support request/thread.

    Thank you and have a nice day.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. could custom field types add a check box ?
    By b2bexpress in forum Help Using ClassiPress
    Replies: 2
    Last Post: June 6th, 2010, 09:42 PM
  2. Creating 2 Concurrent Ad Types in 3.0
    By rmcrmc in forum Help Using ClassiPress
    Replies: 4
    Last Post: April 3rd, 2010, 02:14 PM
  3. Allowing upload of other files types
    By wilson in forum ClassiPress General Discussion
    Replies: 2
    Last Post: October 22nd, 2009, 07:33 PM