'un-mega-posts', 'description' => esc_html__('Display the posts as you want', 'adena') );
WP_Widget::__construct( 'un-mega-posts', esc_html__('UN: Mega Posts', 'adena'), $widget_ops );
}
// Display Widget
function widget( $args, $instance ) {
extract( $args );
//Our variables from the widget settings.
$title = apply_filters('widget_title', empty($instance['title']) ? 'mega.posts' : $instance['title'], $instance, $this->id_base);
if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) ) {
$number = 3;
}
if ( !empty( $instance['orderby'] ) ) {
$orderby = $instance['orderby'];
}else{
$orderby = 'none';
}
if ( !empty( $instance['orderdir'] ) ) {
$orderdir = $instance['orderdir'];
}else{
$orderdir = 'DESC';
}
if ( !empty( $instance['cat_filter'] ) && !in_array('-1', $instance['cat_filter']) ) {
$cat_filter = $instance['cat_filter'];
}else{
$cat_filter = '0';
}
// Query
$qr_args = array (
'post_status' => 'publish',
'pagination' => false,
'posts_per_page' => $number,
'ignore_sticky_posts' => true,
'category__in' => $cat_filter,
'orderby' => $orderby,
'order' => $orderdir,
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array('post-format-link', 'post-format-quote'),
'operator' => 'NOT IN',
),
),
);
$qr = new WP_Query( $qr_args );
$html = '';
// START WIDGET HTML
if ( $qr->have_posts() ) {
$html .= '
';
$html .= '
'.$title.'
';
while ($qr->have_posts()) { $qr->the_post();
$html .= '
'.un_post_exerpt( get_the_ID(), 8, false, $more='...' ).'
'.get_the_date().'
';
}
$html .= '
';
$html .= '';
}
// Print Item
un_echo( $html, 'html' );
// Restore original Post Data
wp_reset_postdata();
}
// Update the widget
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['number'] = (int) $new_instance['number'];
$instance['cat_filter'] = $new_instance['cat_filter'];
$instance['orderby'] = $new_instance['orderby'];
$instance['orderdir'] = $new_instance['orderdir'];
return $instance;
}
function form( $instance ) {
$title = isset($instance['title']) ? esc_attr($instance['title']) : esc_html__('Mega Posts', 'adena');
$number = isset($instance['number']) ? absint($instance['number']) : 3;
$cat_filter = isset($instance['cat_filter']) ? $instance['cat_filter'] : array('-1');
$orderby = isset($instance['orderby']) ? $instance['orderby'] : 'none';
$orderdir = isset($instance['orderdir']) ? $instance['orderdir'] : 'DESC';
?>
'name','order' => 'ASC')); ?>