/** * HTML dropdown list of views timing */ function dp_dropdown_views_timing($args) { $defaults = array('name' => '', 'selected' => '', 'class' => '', 'echo' => true); $args = wp_parse_args($args, $defaults); extract($args); $views_timing = dp_views_timings(); $dropdown = '<select class="' . $class . '" name="' . $name . '">'; foreach ($views_timing as $option => $label) { $dropdown .= '<option value="' . $option . '"' . selected($option, $selected, false) . '>' . $label . '</option>'; } $dropdown .= '</select>'; if ($echo) { echo $dropdown; } else { return $dropdown; } }
function form($instance) { $defaults = array('title' => __('Recent Posts', 'dp'), 'posts_per_page' => 6, 'orderby' => 'date', 'order' => 'desc', 'style' => 'list', 'cat' => '', 'current_cat' => true, 'current_author' => true, 'post__in' => '', 'views_timing' => '', 'style' => 'list'); $instance = wp_parse_args((array) $instance, $defaults); // Styles $styles = array('list' => __('List with Thumbnail', 'dp'), 'list-full' => __('List with Full Width Thumbnail', 'dp'), 'grid-2' => __('2 Columns Grid', 'dp'), 'grid-3' => __('3 Columns Grid', 'dp')); $views_timings = dp_views_timings(); $dropdown_categories = wp_dropdown_categories(array('echo' => 0, 'name' => $this->get_field_name('cat'), 'selected' => $instance['cat'], 'show_option_all' => __('All', 'dp'), 'class' => 'widefat')); $dropdown_sort_types = dp_dropdown_sort_types(array('echo' => 0, 'name' => $this->get_field_name('orderby'), 'selected' => $instance['orderby'], 'class' => 'widefat')); $dropdown_order_types = dp_dropdown_order_types(array('echo' => 0, 'name' => $this->get_field_name('order'), 'selected' => $instance['order'], 'class' => 'widefat')); ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'dp'); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo $instance['title']; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('posts_per_page'); ?> "><?php _e('Number:', 'dp'); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('posts_per_page'); ?> " name="<?php echo $this->get_field_name('posts_per_page'); ?> " value="<?php echo $instance['posts_per_page']; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('orderby'); ?> "><?php _e('Orderby:', 'dp'); ?> </label> <?php echo $dropdown_sort_types; ?> </p> <p> <label for="<?php echo $this->get_field_id('order'); ?> "><?php _e('Order:', 'dp'); ?> </label> <?php echo $dropdown_order_types; ?> </p> <?php if (function_exists('baw_pvc_main')) { ?> <p> <label for="<?php echo $this->get_field_id('views_timing'); ?> "><?php _e('Views Timing:', 'dp'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('views_timing'); ?> " name="<?php echo $this->get_field_name('views_timing'); ?> "> <?php foreach ($views_timings as $option_value => $option_label) { ?> <option value="<?php echo $option_value; ?> " <?php selected($instance['views_timing'], $option_value); ?> ><?php echo $option_label; ?> </option> <?php } ?> </select> </p> <?php } ?> <p> <label for="<?php echo $this->get_field_id('cat'); ?> "><?php _e('Category:', 'dp'); ?> </label> <?php echo $dropdown_categories; ?> </p> <p><input id="<?php echo $this->get_field_id('current_cat'); ?> " name="<?php echo $this->get_field_name('current_cat'); ?> " type="checkbox" <?php checked(!empty($instance['current_cat']) ? $instance['current_cat'] : 0); ?> /> <label for="<?php echo $this->get_field_id('current_cat'); ?> "><?php _e('Limit posts by current category on category archive pages?', 'dp'); ?> </label></p> <p><input id="<?php echo $this->get_field_id('current_author'); ?> " name="<?php echo $this->get_field_name('current_author'); ?> " type="checkbox" <?php checked(!empty($instance['current_author']) ? $instance['current_author'] : 0); ?> /> <label for="<?php echo $this->get_field_id('current_author'); ?> "><?php _e('Limit posts by current author on author archive pages?', 'dp'); ?> </label></p> <p> <label for="<?php echo $this->get_field_id('post__in'); ?> "><?php _e('Includes:', 'dp'); ?> </label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('post__in'); ?> " name="<?php echo $this->get_field_name('post__in'); ?> " value="<?php echo $instance['post__in']; ?> " /> </p> <p class="description"> <?php _e('If you want to display specific posts, enter post ids to here, separate ids with commas, (e.g. 1,2,3,4). <br />if this field is not empty, category will be ignored. <br/>If you want to display posts sort by the order of your enter IDs, set "Sort" field as <strong>None</strong>.', 'dp'); ?> </p> <p> <label for="<?php echo $this->get_field_id('style'); ?> "><?php _e('Style:', 'dp'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('style'); ?> " name="<?php echo $this->get_field_name('style'); ?> "> <?php foreach ($styles as $option_value => $option_label) { ?> <option value="<?php echo $option_value; ?> " <?php selected($instance['style'], $option_value); ?> ><?php echo $option_label; ?> </option> <?php } ?> </select> </p> <?php }