$this->widget_cssclass, 'description' => $this->widget_description ); parent::__construct( $this->widget_id, $this->widget_name, $widget_ops ); } /** * update function. * * @see WP_Widget->update * @param array $new_instance * @param array $old_instance * @return array */ public function update( $new_instance, $old_instance ) { $instance = $old_instance; if ( ! $this->settings ) { return $instance; } foreach ( $this->settings as $key => $setting ) { if(isset($setting['multiple'])): $instance[ $key ] = implode ( ',', $new_instance [$key] ); else: if ( isset( $new_instance[ $key ] ) ) { $instance[ $key ] = sanitize_text_field( $new_instance[ $key ] ); } elseif ( 'checkbox' === $setting['type'] ) { $instance[ $key ] = 0; } endif; } if($this->cached){ $this->flush_widget_cache(); } return $instance; } /** * form function. * * @see WP_Widget->form * @param array $instance */ public function form( $instance ) { if ( ! $this->settings ) { return; } foreach ( $this->settings as $key => $setting ) { $value = isset( $instance[ $key ] ) ? $instance[ $key ] : $setting['std']; switch ( $setting['type'] ) { case "text" : ?>

/>

'name', 'order' => 'DESC', ); $post_categories = get_categories($args); $post_category[esc_html__( '--Select--', 'webgame' )] = ''; foreach ( $post_categories as $p_cat ) { $post_category[$p_cat->slug] = $p_cat->name; } return $post_category; } class webgame_Posts extends Gamota_Widget{ public function __construct(){ $this->widget_cssclass = 'webgame_posts__wg'; $this->widget_description = esc_html__( "A list of Your site’s Posts.", 'webgame' ); $this->widget_id = 'webgame_Posts_Widget'; $this->widget_name = esc_html__( 'Webgame Posts', 'webgame' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' =>'', 'label' => esc_html__( 'Title', 'webgame' ) ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => esc_html__( 'Order by', 'webgame' ), 'options' => array( 'date' => esc_html__( 'Recent posts', 'webgame' ), 'featured' => esc_html__( 'Featured posts', 'webgame' ), 'rand' => esc_html__( 'Random', 'webgame' ), ) ), 'number' => array( 'type' => 'number', 'std' => '4', 'label' => esc_html__( 'Number of posts to show:', 'webgame' ) ), 'show_date' => array( 'type' => 'checkbox', 'std' =>'', 'label' => esc_html__( 'Display post date?', 'webgame' ) ), ); parent::__construct(); } public function widget($args, $instance){ ob_start(); extract( $args ); $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); $orderby = sanitize_title( $instance['orderby'] ); $number = isset($instance['number']) ? absint($instance['number']) : 4 ; $show_date = isset($instance['show_date']) ? $instance['show_date'] : ''; echo $before_widget; if($title) { echo wp_kses( $before_title . esc_html($title) . $after_title, array( 'h3' => array( 'class' => array() ), 'h4' => array( 'class' => array() ), 'span' => array( 'class' => array() ), ) ); } switch ($orderby) { case 'date': $orderby = 'date'; break; case 'featured': $orderby = 'meta_value'; break; case 'rand': $orderby = 'rand'; break; default: $orderby = 'date'; break; } $args = array( 'post_type' => 'post', 'posts_per_page' => $number , 'order' => 'DESC', 'orderby' => "{$orderby}", 'ignore_sticky_posts' => true, 'post_status' => 'publish' ); if( $orderby == 'meta_value' ){ $args['meta_key'] = '_webgame_post_meta_featured_post'; $args['meta_value'] = 'yes'; } $posts = new WP_Query($args); if($posts->have_posts()): ?>
    have_posts()): $posts->the_post(); ?>
widget_cssclass = 'webgame_tab-category-posts__wg'; $this->widget_description = esc_html__( "Display Posts in the tab category.", 'webgame' ); $this->widget_id = 'webgame_Tab_Category_Posts'; $this->widget_name = esc_html__( 'Webgame Tab Category Posts', 'webgame' ); $this->settings = array( 'title' => array( 'type' => 'text', 'std' =>'', 'label' => esc_html__( 'Title', 'webgame' ) ), 'categories' => array( 'type' => 'select', 'multiple'=> true, 'std' => '', 'label' => esc_html__( 'Select category*', 'webgame' ), 'options' => webgame_get_post_category(), ), 'orderby' => array( 'type' => 'select', 'std' => 'date', 'label' => esc_html__( 'Order by', 'webgame' ), 'options' => array( 'date' => esc_html__( 'Order by date', 'webgame' ), 'title' => esc_html__( 'Order by title', 'webgame' ), 'rand' => esc_html__( 'Random', 'webgame' ), ) ), 'order' => array( 'type' => 'select', 'std' => 'DESC', 'label' => esc_html__( 'Order', 'webgame' ), 'options' => array( 'DESC' => esc_html__( 'Order DESC', 'webgame' ), 'ASC' => esc_html__( 'Order ASC', 'webgame' ), ) ), 'posts_per_page' => array( 'type' => 'number', 'std' => '10', 'label' => esc_html__( 'Number of posts to query:', 'webgame' ) ), ); parent::__construct(); } public function widget($args, $instance){ ob_start(); extract( $args ); $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); $categories = isset($instance['categories']) ? explode(',',$instance['categories']) : array(); $orderby = sanitize_title( $instance['orderby'] ); $order = $instance['order'] ; $posts_per_page = isset($instance['posts_per_page']) ? absint($instance['posts_per_page']) : 10 ; echo $before_widget; if($title) { echo wp_kses( $before_title . esc_html($title) . $after_title, array( 'h3' => array( 'class' => array() ), 'h4' => array( 'class' => array() ), 'span' => array( 'class' => array() ), ) ); } if( !empty($categories) ):?>
= 3) { $c_name = 'more__categories'; } ?>
    '.$cat->name.''; $i++; } ?>
      '.$cat->name.''; $i++; } ?>
    */ ?>
$category, 'post_type' => 'post', 'posts_per_page' => $posts_per_page , 'orderby' => "{$orderby}", 'order' => "{$order}", 'ignore_sticky_posts' => true, 'post_status' => 'publish', // 'tax_query' => array( // array( // 'taxonomy' => 'post_format', // 'field' => 'slug', // 'terms' => array( 'post-format-aside' ) // ) // ), 'paged' => $paged ); //echo $order; die(); $posts = new WP_Query($args); if($posts->have_posts()): $firstPost = true; ?>
    have_posts()): $posts->the_post(); ?>
  • []