/** * wpsc_list_categories function. * * @access public * @param string $callback_function - The function name you want to use for displaying the data * @param mixed $parameters (default: null) - the additional parameters to the callback function * @param int $category_id. (default: 0) - The category id defaults to zero, for displaying all categories * @param int $level. (default: 0) */ function wpsc_list_categories($callback_function, $parameters = null, $category_id = 0, $level = 0) { global $wpdb, $category_data; $output = ''; $category_list = get_terms('wpsc_product_category', 'hide_empty=0&parent=' . $category_id); if ($category_list != null) { foreach ((array) $category_list as $category) { $callback_output = $callback_function($category, $level, $parameters); if (is_array($callback_output)) { $output .= array_shift($callback_output); } else { $output .= $callback_output; } $output .= wpsc_list_categories($callback_function, $parameters, $category->term_id, $level + 1); if (is_array($callback_output) && isset($callback_output[1])) { $output .= $callback_output[1]; } } } return $output; }
/** * Widget Options Form * * @param $instance (array) Widget values. */ function form($instance) { global $wpdb; // Defaults $instance = wp_parse_args((array) $instance, array('title' => '', 'width' => 45, 'height' => 45, 'image' => false, 'grid' => false, 'show_name' => false)); // Values $title = esc_attr($instance['title']); $image = (bool) $instance['image']; $width = (int) $instance['width']; $height = (int) $instance['height']; $grid = (bool) $instance['grid']; $show_name = (bool) $instance['show_name']; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'wpsc'); ?> </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> <?php _e('Show Categories', 'wpsc'); ?> :<br /> <?php wpsc_list_categories('wpsc_category_widget_admin_category_list', array("id" => $this->get_field_id('categories'), "name" => $this->get_field_name('categories'), "instance" => $instance), 0); ?> <?php _e('(leave all unchecked if you want to display all)', 'wpsc'); ?> </p> <p> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('grid'); ?> " name="<?php echo $this->get_field_name('grid'); ?> "<?php checked($grid); ?> /> <label for="<?php echo $this->get_field_id('grid'); ?> "><?php _e('Use Category Grid View', 'wpsc'); ?> </label><br /> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('image'); ?> " name="<?php echo $this->get_field_name('image'); ?> "<?php checked($image); ?> onclick="jQuery('.wpsc_category_image').toggle()" /> <label for="<?php echo $this->get_field_id('image'); ?> "><?php _e('Show Thumbnails', 'wpsc'); ?> </label> </p> <div class="wpsc_category_image"<?php if (!checked($image)) { echo ' style="display:none;"'; } ?> > <p> <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_name'); ?> " name="<?php echo $this->get_field_name('show_name'); ?> "<?php checked($show_name); ?> /><label for="<?php echo $this->get_field_id('show_name'); ?> "><?php _e(' Show N/A when No Image Available', 'wpsc'); ?> </label> </p> <p> <label for="<?php echo $this->get_field_id('width'); ?> "><?php _e('Width:', 'wpsc'); ?> </label> <input type="text" id="<?php echo $this->get_field_id('width'); ?> " name="<?php echo $this->get_field_name('width'); ?> " value="<?php echo $width; ?> " size="3" /> <label for="<?php echo $this->get_field_id('height'); ?> "><?php _e('Height:', 'wpsc'); ?> </label> <input type="text" id="<?php echo $this->get_field_id('height'); ?> " name="<?php echo $this->get_field_name('height'); ?> " value="<?php echo $height; ?> " size="3" /> </p> </div> <?php }
} global $categories, $cat_asoc; $categories = array(); $cat_asoc = array(); function list_categories_callback($category, $level, $parameters) { global $categories, $cat_asoc; $cat = new stdClass(); $cat->category_id = $category->term_id; $cat->category_name = $category->name; $cat->category_slug = urldecode($category->slug); $cat->category_parent = $category->parent; $categories[] = $cat; $cat_asoc[$cat->category_id] = $cat; } $res = wpsc_list_categories('list_categories_callback'); $_num_sample = 1 / 2 . ''; $args = array('post_type' => array('wpsc-product', 'wpsc-variation'), 'posts_per_page' => -1, 'ignore_sticky_posts' => false, 'orderby' => $orderby, 'order' => $sort_order, 'fields' => 'ids'); if ($product_status) { $args['post_status'] = $product_status; } else { $args['post_status'] = 'any'; } if ($orderby_key) { $args['meta_key'] = $orderby_key; } $meta_query = array(); if (isset($product_name)) { global $wpdb; $name_postids = $wpdb->get_col("select ID from {$wpdb->posts} where post_title like '%{$product_name}%' "); $args['post__in'] = empty($name_postids) ? array(-9999) : $name_postids;