array( 'name' => esc_html__( 'Posts', 'mega' ), 'description' => esc_html__( 'Recent, popular & random posts block', 'mega' )), 'universal' => true, 'class_base'=> 'ys-recent-posts' ); parent::__construct( __CLASS__, $args ); } public function settings( $form ) { $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Title', 'mega' ), 'value' => esc_html__( 'Blog Posts', 'mega' ), 'name' => 'title' )); $form->add_control( 'Mega_Control_Number', array( 'label' => esc_html__( 'Title length', 'mega' ), 'value' => 40, 'name' => 'title_length' )); $form->add_control( 'Mega_Control_Select', array( 'label' => esc_html__( 'Order By', 'mega' ), 'pro' => 1, 'value' => 'date', 'name' => 'order', 'choices' => array( 'date' => esc_html__( 'Date', 'mega' ), 'rand' => esc_html__( 'Random', 'mega' ), 'comment_count' => esc_html__( 'Comment Count', 'mega' ) ) )); $form->add_control( 'Mega_Control_Number', array( 'label' => esc_html__( 'Number of Results', 'mega' ), 'pro' => 1, 'value' => 3, 'name' => 'count' )); $form->add_control( 'Mega_Control_Select', array( 'label' => esc_html__( 'Select a Category', 'mega' ), 'name' => 'cat', 'use_list' => 1, 'list' => 'mega_cat_list' )); $form->add_control( 'Mega_Control_onOff', array( 'label' => esc_html__( 'Image', 'mega' ), 'value' => 1, 'name' => 'image' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'image', 'control_value' => 'true', 'label' => esc_html__( 'Image Width (px)', 'mega' ), 'value' => 28, 'name' => 'width' )); $form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'image', 'control_value' => 'true', 'label' => esc_html__( 'Image Height (px)', 'mega' ), 'value' => 28, 'name' => 'height' )); $form->add_sub_control( 'Mega_Control_Checklist', array( 'control' => 'image', 'control_value' => 'true', 'label' => esc_html__( 'Image Sources', 'mega' ), 'value' => array( 'featured' => 1, 'first' => 1, 'ph' => 1 ), 'name' => 'sources', 'choices' => array( 'featured' => esc_html__( 'Featured', 'mega' ), 'first' => esc_html__( 'First', 'mega' ), 'ph' => esc_html__( 'Placeholder', 'mega' ) ) )); $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Layout', 'mega' ), 'desc' => wp_kses( __( 'Use [title], [excerpt] and [meta] snippets to format the layout order.

Title - [title]
Excerpt - [excerpt]
Meta - [meta]', 'mega' ), array( 'br' => true, 'strong' => true )), 'pro' => 1, 'value' => '[title][meta]', 'name' => 'layout' )); $form->add_control( 'Mega_Control_Number', array( 'label' => esc_html__( 'Excerpt length', 'mega' ), 'value' => 40, 'name' => 'length' )); $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Meta', 'mega' ), 'desc' => wp_kses( __( 'Use [date], [comments] and [author] snippets to format the meta order.

Date - [date]
Comments - [comments]
Author - [author]', 'mega' ), array( 'br' => true, 'strong' => true )), 'pro' => 1, 'value' => '[comments][date]', 'name' => 'meta' )); $form->add_control( 'Mega_Control_Text', array( 'label' => esc_html__( 'Date Format', 'mega' ), 'value' => esc_html__( 'F jS, Y', 'mega' ), 'name' => 'date' )); } public function block() { extract( $this->mega['settings'] ); $query = new WP_Query( array( 'post_type' => 'post', 'orderby' => $order, 'ignore_sticky_posts' => 1, 'posts_per_page' => $count, 'cat' => $cat )); echo ''; } public function post() { extract( $this->mega['settings'] ); echo '
  • '; //print_r($sources); if ( $image ) mega_thumb( array( 'width' => $width . 'px', 'height' => $height, 'sources' => $sources )); echo mega_parse_message( array( 'title' => sprintf( '%3$s', esc_url( get_permalink() ), esc_attr( sprintf( esc_html__( 'Permalink to %s', 'mega' ), get_the_title() )), esc_html( substr( get_the_title(), 0, $title_length )) ), 'excerpt' => '
    ' . esc_html( substr( get_the_excerpt(), 0, $length )) . ' ...
    ', 'meta' => mega_parse_message( array( 'date' => $this->getMeta( 'date', $this->mega ), 'comments' => $this->getMeta( 'comments', $this->mega ), 'author' => $this->getMeta( 'author', $this->mega ) ), '
    ' . $meta . '
    ' ) ), $layout ); echo '
  • '; } public function getMeta( $item, $instance ) { return mega_html( esc_html( $this->getWrap( $item, $instance )), '', '', false ); } public function getWrap( $item, $instance ) { extract( $instance['settings'] ); switch( $item ) { case 'date' : return get_the_date( $date ); case 'comments' : return !post_password_required() ? sprintf( esc_html__( '%s Comments', 'mega' ), get_comments_number() ) : ''; case 'author' : return sprintf( esc_html__( 'By %s', 'mega' ), get_the_author() ); } } }