'热门文章排行' ) ); } function form($instance) { $num = isset($instance['number']) ? absint($instance['number']) : 5; $title = isset($instance['title']) ? $instance['title'] : '热门文章'; $type = isset($instance['type']) ? $instance['type'] : 'comment'; ?>

id_base)) { echo $args['before_title'] . $title . $args['after_title']; } } public function widget_end($args) { echo $args['after_widget']; } function update($new_instance, $old_instance) { /* $instance = $old_instance; $instance['num'] = absint($new_instance['num']); $instance['title'] = sanitize_text_field($new_instance['title']);*/ return $new_instance; } function widget($args, $instance) { $this->widget_start($args, $instance); $number = (!empty($instance['number'])) ? absint($instance['number']) : 5; $type = (!empty($instance['type'])) ? $instance['type'] : 'comment'; if ($type == 'comment') { $the_query = new WP_Query(array('order' => 'DESC', 'orderby' => 'comment_count', 'posts_per_page' => $number)); } elseif ($type == 'view') { $the_query = new WP_Query(array('order' => 'DESC', 'orderby' => 'meta_value_num', 'meta_key'=>'views','posts_per_page' => $number)); } if ($the_query->have_posts()) { $postitem = array(); $i = 0; while ($the_query->have_posts()) { $i++; $the_query->the_post(); $postitem['title'] = get_the_title(); $postitem['time'] = get_the_time('Y-m-d'); $postitem['category'] = get_the_category(); $postitem['url'] = get_the_permalink(); ?>
name ?>
widget_end($args, $instance); } } // register widget function register_corepress_hot_post_widget() { register_widget('CorePress_hot_post_widget'); } add_action('widgets_init', 'register_corepress_hot_post_widget');