function form($instance) { $default = array('title' => '', 'categories' => array(), 'relation' => 'OR', 'tags' => array(), 'number_of_article' => 8, 'orderby' => 'latest', 'kopa_timestamp' => '', 'animation' => 'slide', 'direction' => 'horizontal', 'slideshowSpeed' => 7000, 'animationSpeed' => 600, 'isAutoplay' => 'true'); $instance = wp_parse_args((array) $instance, $default); $title = strip_tags($instance['title']); $form['categories'] = $instance['categories']; $form['relation'] = esc_attr($instance['relation']); $form['tags'] = $instance['tags']; $form['number_of_article'] = (int) $instance['number_of_article']; $form['orderby'] = $instance['orderby']; $form['animation'] = $instance['animation']; $form['direction'] = $instance['direction']; $form['slideshowSpeed'] = (int) $instance['slideshowSpeed']; $form['animationSpeed'] = (int) $instance['animationSpeed']; $form['kopa_timestamp'] = $instance['kopa_timestamp']; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php echo __('Title:', kopa_get_domain()); ?> </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 esc_attr($title); ?> " /> </p> <div class="kopa-one-half"> <p> <label for="<?php echo $this->get_field_id('categories'); ?> "><?php echo __('Categories:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('categories'); ?> " name="<?php echo $this->get_field_name('categories'); ?> []" multiple="multiple" size="5" autocomplete="off"> <option value=""><?php echo __('-- None --', kopa_get_domain()); ?> </option> <?php $categories = get_categories(); foreach ($categories as $category) { printf('<option value="%1$s" %4$s>%2$s (%3$s)</option>', $category->term_id, $category->name, $category->count, in_array($category->term_id, isset($form['categories']) ? $form['categories'] : array()) ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('relation'); ?> "><?php echo __('Relation:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('relation'); ?> " name="<?php echo $this->get_field_name('relation'); ?> " autocomplete="off"> <?php $relation = array('AND' => __('And', kopa_get_domain()), 'OR' => __('Or', kopa_get_domain())); foreach ($relation as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['relation'] ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('tags'); ?> "><?php echo __('Tags:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('tags'); ?> " name="<?php echo $this->get_field_name('tags'); ?> []" multiple="multiple" size="5" autocomplete="off"> <option value=""><?php echo __('-- None --', kopa_get_domain()); ?> </option> <?php $tags = get_tags(); foreach ($tags as $tag) { printf('<option value="%1$s" %4$s>%2$s (%3$s)</option>', $tag->term_id, $tag->name, $tag->count, in_array($tag->term_id, isset($form['tags']) ? $form['tags'] : array()) ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('number_of_article'); ?> "><?php echo __('Number of articles', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('number_of_article'); ?> " name="<?php echo $this->get_field_name('number_of_article'); ?> " type="number" value="<?php echo $form['number_of_article']; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('orderby'); ?> "><?php echo __('Orderby:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('orderby'); ?> " name="<?php echo $this->get_field_name('orderby'); ?> " autocomplete="off"> <?php $orderby = array('latest' => __('Latest', kopa_get_domain()), 'popular' => __('Popular by View Count', kopa_get_domain()), 'most_comment' => __('Popular by Comment Count', kopa_get_domain()), 'random' => __('Random', kopa_get_domain())); foreach ($orderby as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['orderby'] ? 'selected="selected"' : ''); } ?> </select> </p> <?php kopa_print_timeago($this->get_field_id('kopa_timestamp'), $this->get_field_name('kopa_timestamp'), $form['kopa_timestamp']); ?> </div> <div class="kopa-one-half last"> <p> <label for="<?php echo $this->get_field_id('animation'); ?> "><?php echo __('Animation:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('animation'); ?> " name="<?php echo $this->get_field_name('animation'); ?> " autocomplete="off"> <?php $relation = array('fade' => __('Fade', kopa_get_domain()), 'slide' => __('Slide', kopa_get_domain())); foreach ($relation as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['animation'] ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('direction'); ?> "><?php echo __('Direction:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('direction'); ?> " name="<?php echo $this->get_field_name('direction'); ?> " autocomplete="off"> <?php $relation = array('horizontal' => __('Horizontal', kopa_get_domain())); foreach ($relation as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['direction'] ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('slideshowSpeed'); ?> "><?php echo __('Slideshow Speed (ms):', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('slideshowSpeed'); ?> " name="<?php echo $this->get_field_name('slideshowSpeed'); ?> " type="number" value="<?php echo $form['slideshowSpeed']; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('animationSpeed'); ?> "><?php echo __('Animation Speed (ms):', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('animationSpeed'); ?> " name="<?php echo $this->get_field_name('animationSpeed'); ?> " type="number" value="<?php echo $form['animationSpeed']; ?> " /> </p> <p> <input class="checkbox" type="checkbox" <?php checked($instance['isAutoplay'], 'true', true); ?> id="<?php echo $this->get_field_id('isAutoplay'); ?> " name="<?php echo $this->get_field_name('isAutoplay'); ?> " value="true" /> <label for="<?php echo $this->get_field_id('isAutoplay'); ?> "><?php echo __('Auto play slider', kopa_get_domain()); ?> </label> </p> </div> <div class="kopa-clear"></div> <?php }
function form($instance) { $defaults = array('title' => '', 'categories' => array(), 'relation' => 'OR', 'tags' => array(), 'number_of_article' => 1, 'orderby' => 'latest', 'kopa_timestamp' => ''); $instance = wp_parse_args((array) $instance, $defaults); $title = strip_tags($instance['title']); $form['categories'] = $instance['categories']; $form['relation'] = esc_attr($instance['relation']); $form['tags'] = $instance['tags']; $form['number_of_article'] = $instance['number_of_article']; $form['orderby'] = $instance['orderby']; $form['kopa_timestamp'] = $instance['kopa_timestamp']; ?> <p> <label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', kopa_get_domain()); ?> </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 esc_attr($title); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('categories'); ?> "><?php _e('Categories:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('categories'); ?> " name="<?php echo $this->get_field_name('categories'); ?> []" multiple="multiple" size="5" autocomplete="off"> <option value=""><?php _e('-- None --', kopa_get_domain()); ?> </option> <?php $categories = get_categories(); foreach ($categories as $category) { printf('<option value="%1$s" %4$s>%2$s (%3$s)</option>', $category->term_id, $category->name, $category->count, in_array($category->term_id, $form['categories']) ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('relation'); ?> "><?php _e('Relation:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('relation'); ?> " name="<?php echo $this->get_field_name('relation'); ?> " autocomplete="off"> <?php $relation = array('AND' => __('And', kopa_get_domain()), 'OR' => __('Or', kopa_get_domain())); foreach ($relation as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['relation'] ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('tags'); ?> "><?php _e('Tags:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('tags'); ?> " name="<?php echo $this->get_field_name('tags'); ?> []" multiple="multiple" size="5" autocomplete="off"> <option value=""><?php _e('-- None --', kopa_get_domain()); ?> </option> <?php $tags = get_tags(); foreach ($tags as $tag) { printf('<option value="%1$s" %4$s>%2$s (%3$s)</option>', $tag->term_id, $tag->name, $tag->count, in_array($tag->term_id, $form['tags']) ? 'selected="selected"' : ''); } ?> </select> </p> <p> <label for="<?php echo $this->get_field_id('number_of_article'); ?> "><?php _e('Number of article:', kopa_get_domain()); ?> </label> <input class="widefat" type="number" min="1" id="<?php echo $this->get_field_id('number_of_article'); ?> " name="<?php echo $this->get_field_name('number_of_article'); ?> " value="<?php echo esc_attr($form['number_of_article']); ?> "> </p> <p> <label for="<?php echo $this->get_field_id('orderby'); ?> "><?php _e('Orderby:', kopa_get_domain()); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('orderby'); ?> " name="<?php echo $this->get_field_name('orderby'); ?> " autocomplete="off"> <?php $orderby = array('latest' => __('Latest', kopa_get_domain()), 'popular' => __('Popular by View Count', kopa_get_domain()), 'most_comment' => __('Popular by Comment Count', kopa_get_domain()), 'random' => __('Random', kopa_get_domain())); foreach ($orderby as $value => $title) { printf('<option value="%1$s" %3$s>%2$s</option>', $value, $title, $value === $form['orderby'] ? 'selected="selected"' : ''); } ?> </select> </p> <?php kopa_print_timeago($this->get_field_id('kopa_timestamp'), $this->get_field_name('kopa_timestamp'), $form['kopa_timestamp']); ?> <?php }
function form($instance) { $instance = wp_parse_args((array) $instance, array('title1' => __('Latest', kopa_get_domain()), 'num1' => 5, 'title2' => __('Popular', kopa_get_domain()), 'num2' => 5, 'title3' => __('Most comment', kopa_get_domain()), 'num3' => 5, 'title4' => __('Random', kopa_get_domain()), 'num4' => 5, 'kopa_timestamp' => '')); $title1 = strip_tags($instance['title1']); $num1 = strip_tags($instance['num1']); $title2 = strip_tags($instance['title2']); $num2 = strip_tags($instance['num2']); $title3 = strip_tags($instance['title3']); $num3 = strip_tags($instance['num3']); $title4 = strip_tags($instance['title4']); $num4 = strip_tags($instance['num4']); $form['kopa_timestamp'] = $instance['kopa_timestamp']; ?> <p> <label for="<?php echo $this->get_field_id('title1'); ?> "><?php echo __('Latest post title:', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title1'); ?> " name="<?php echo $this->get_field_name('title1'); ?> " type="text" value="<?php echo esc_attr($title1); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('num1'); ?> "><?php echo __('Number of latest posts', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('num1'); ?> " name="<?php echo $this->get_field_name('num1'); ?> " type="number" value="<?php echo $num1; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('title2'); ?> "><?php echo __('Most viewed title:', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title2'); ?> " name="<?php echo $this->get_field_name('title2'); ?> " type="text" value="<?php echo esc_attr($title2); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('num2'); ?> "><?php echo __('Number of most viewed posts', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('num2'); ?> " name="<?php echo $this->get_field_name('num2'); ?> " type="number" value="<?php echo $num2; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('title3'); ?> "><?php echo __('Most comment title:', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title3'); ?> " name="<?php echo $this->get_field_name('title3'); ?> " type="text" value="<?php echo esc_attr($title3); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('num3'); ?> "><?php echo __('Number of most comment posts', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('num3'); ?> " name="<?php echo $this->get_field_name('num3'); ?> " type="number" value="<?php echo $num3; ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('title4'); ?> "><?php echo __('Random title:', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title4'); ?> " name="<?php echo $this->get_field_name('title4'); ?> " type="text" value="<?php echo esc_attr($title4); ?> " /> </p> <p> <label for="<?php echo $this->get_field_id('num4'); ?> "><?php echo __('Number of random posts', kopa_get_domain()); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('num4'); ?> " name="<?php echo $this->get_field_name('num4'); ?> " type="number" value="<?php echo $num4; ?> " /> </p> <?php kopa_print_timeago($this->get_field_id('kopa_timestamp'), $this->get_field_name('kopa_timestamp'), $form['kopa_timestamp']); ?> <?php }