array( 'name' => esc_html__( 'Posts Ajax', 'mega' ), 'description' => esc_html__( 'Recent, popular & random posts block', 'mega' )),
'universal' => true,
'true-wrapper' => false,
'class_base' => 'ys-timeline ys-timeline-posts'
);
add_action( 'wp_ajax_nopriv_timeline_ajax', array( $this, 'ajaxRequest' ));
add_action( 'wp_ajax_timeline_ajax', array( $this, 'ajaxRequest' ));
parent::__construct( $id, $args );
}
public function hookOnce()
{
//if ( !mega_is_mobile() )
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue' ));
}
public function enqueue()
{
wp_enqueue_script( 'mega.jquery.posts.timeline', MEGA_DIR_URI . '/assets/js/mega.jquery.posts.timeline.js', array( 'jquery' ), false, true );
}
public function settings( $form )
{
$form->add_control( 'Mega_Control_Select', array( 'label' => esc_html__( 'Order By', 'mega' ), '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' ), 'value' => 8, '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 (%)', 'mega' ), 'value' => 100, 'name' => 'width' ));
$form->add_sub_control( 'Mega_Control_Number', array( 'control' => 'image', 'control_value' => 'true', 'label' => esc_html__( 'Image Max Height (px)', 'mega' ), 'value' => 200, 'name' => 'max_height' ));
$form->add_sub_control( 'Mega_Control_onOff', array( 'control' => 'image', 'control_value' => 'true', 'label' => esc_html__( 'Pull images from post meta using prefixed meta key: Theme-Name_thumb', 'mega' ), 'value' => false, 'name' => 'image_source_meta' ));
$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 )), 'value' => '[title][excerpt]', '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 )), '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'] );
$page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query( array(
'post_type' => 'post',
'orderby' => $order,
//'ignore_sticky_posts' => 1,
'posts_per_page' => mega_is_mobile() && $count > 3 ? 3 : $count,
'cat' => $cat,
'paged' => $page
));
echo '