'', 'order' => 'DESC', 'orderby' => 'date', 'select' => 'all', 'show' => 6, 'cats' => array(), 'round_images' => true, 'thumbnails' => true, 'images_dimensions' => array( 'w' => 40, 'h' => 40 ) ); /* Widget setup */ function __construct() { /* Widget settings. */ $widget_ops = array( 'description' => _x( 'Blog posts', 'widget', 'the7mk2' ) ); /* Create the widget. */ parent::__construct( 'presscore-blog-posts', DT_WIDGET_PREFIX . _x( 'Blog posts', 'widget', 'the7mk2' ), $widget_ops ); } /* Display the widget */ function widget( $args, $instance ) { extract( $args ); $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); /* Our variables from the widget settings. */ $title = apply_filters( 'widget_title', $instance['title'] ); $terms = empty($instance['cats']) ? array(0) : (array) $instance['cats']; $html = ''; if ( $terms ) { $attachments_data = presscore_get_related_posts( array( 'exclude_current' => false, 'cats' => $terms, 'select' => $instance['select'], 'post_type' => 'post', 'taxonomy' => 'category', 'field' => 'term_id', 'args' => array( 'posts_per_page' => $instance['show'], 'orderby' => $instance['orderby'], 'order' => $instance['order'], ) ) ); $list_args = array( 'show_images' => (boolean) $instance['thumbnails'], 'image_dimensions' => $instance['images_dimensions'] ); $posts_list = presscore_get_posts_small_list( $attachments_data, $list_args ); if ( $posts_list ) { foreach ( $posts_list as $p ) { $html .= sprintf( '
  • %s
  • ', $p ); } $html = ''; } } echo $before_widget ; // title if ( $title ) echo $before_title . $title . $after_title; echo $html; echo $after_widget; } /* Update the widget settings */ function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['order'] = esc_attr($new_instance['order']); $instance['orderby'] = esc_attr($new_instance['orderby']); $instance['show'] = intval($new_instance['show']); $instance['select'] = in_array( $new_instance['select'], array('all', 'only', 'except') ) ? $new_instance['select'] : 'all'; $instance['cats'] = (array) $new_instance['cats']; if ( empty($instance['cats']) ) { $instance['select'] = 'all'; } $instance['thumbnails'] = absint($new_instance['thumbnails']); $instance['round_images'] = absint($new_instance['round_images']); $instance['images_dimensions'] = array_map( 'absint', $new_instance['images_dimensions'] ); return $instance; } /** * Displays the widget settings controls on the widget panel. * Make use of the get_field_id() and get_field_name() function * when creating your form elements. This handles the confusing stuff. */ function form( $instance ) { /* Set up some default widget settings. */ $instance = wp_parse_args( (array) $instance, self::$widget_defaults ); $terms = get_terms( 'category', array( 'hide_empty' => 1, 'hierarchical' => false ) ); $orderby_list = array( 'ID' => _x( 'Order by ID', 'widget', 'the7mk2' ), 'author' => _x( 'Order by author', 'widget', 'the7mk2' ), 'title' => _x( 'Order by title', 'widget', 'the7mk2' ), 'date' => _x( 'Order by date', 'widget', 'the7mk2' ), 'modified' => _x( 'Order by modified', 'widget', 'the7mk2' ), 'rand' => _x( 'Order by rand', 'widget', 'the7mk2' ), 'menu_order'=> _x( 'Order by menu', 'widget', 'the7mk2' ) ); ?>


    term_id, $instance['cats']) ); ?> />