'strtm-post-widget', 'description' => 'Canopus recent posts.'); parent::__construct('strtm-post-widget', 'Canopus: Recent posts', $widget_ops); } function widget($args, $instance) { global $post; extract($args); $title = apply_filters('widget_title', $instance['title']); $q['posts_per_page'] = isset($instance['number_posts'])?$instance['number_posts']:5; $cats = (array) $instance['post_category']; $q['paged'] = 1; if(count($cats) > 0){ $typ = 'category'; $sp = ''; $catq = ''; foreach ($cats as $mycat) { $catq = $catq . $sp . $mycat; $sp = ','; } $catq = explode(',', $catq); $q['tax_query'] = Array(Array( 'taxonomy' => $typ, 'terms' => $catq, 'field' => 'id' ) ); } if($instance['post_order']==='commented'){ $q['orderby'] = 'comment_count'; }elseif($instance['post_order'] == 'popular'){ $q['orderby'] = 'meta_value_num'; $q['meta_key'] = 'post_seen'; } $post_query = new WP_Query( $q ); if (isset($before_widget)){echo ($before_widget);} if ($title != ''){echo balanceTags($args['before_title'] . $title . $args['after_title']);} if(!empty($instance['post_layout'])){ wp_enqueue_script('owl-carousel'); echo ''; }else{ echo ''; } if (isset($after_widget)){echo ($after_widget);} wp_reset_postdata(); } function update($new_instance, $old_instance) { $instance = $old_instance; /* Strip tags (if needed) and update the widget settings. */ $instance['title'] = sanitize_text_field($new_instance['title']); $instance['post_category'] = $_REQUEST['post_category']; $instance['number_posts'] = strip_tags($new_instance['number_posts']); $instance['post_order'] = strip_tags($new_instance['post_order']); $instance['post_layout'] = strip_tags($new_instance['post_layout']); $instance['height'] = strip_tags($new_instance['height']); return $instance; } function form($instance) { //Output admin widget options form extract(shortcode_atts(array( 'title' => '', 'number_posts' => 5, 'post_order' => 'latest', 'post_type' => 'post', 'post_layout' => '', 'height' => '' ), $instance)); ?>

$tax[0], 'checked_ontop' => false, 'selected_cats' => $selctedcat)); ?>