widget_cssclass = 'blogcorner-widget-advanced-recent';
$this->widget_description = __("Displays featured posts with an image", 'blogcorner');
$this->widget_id = 'Blogcorner_Advanced_Recent_Widget';
$this->widget_name = __('Blogcorner: Advanced Recent Post', 'blogcorner');
$this->settings = array(
'title' => array(
'type' => 'text',
'label' => __('Title', 'blogcorner'),
),
'category' => array(
'type' => 'dropdown-taxonomies',
'label' => __('Select Category', 'blogcorner'),
'desc' => __('Leave empty if you don\'t want the posts to be category specific', 'blogcorner'),
'args' => array(
'taxonomy' => 'category',
'class' => 'widefat',
'hierarchical' => true,
'show_count' => 1,
'show_option_all' => __('— Select —', 'blogcorner'),
),
),
'show_category' => array(
'type' => 'checkbox',
'label' => __('Show Category', 'blogcorner'),
'std' => false,
),
'show_description' => array(
'type' => 'checkbox',
'label' => __('Show Description', 'blogcorner'),
'std' => true,
),
'show_author' => array(
'type' => 'checkbox',
'label' => __('Show Author', 'blogcorner'),
'std' => false,
),
'show_date' => array(
'type' => 'checkbox',
'label' => __('Show Date', 'blogcorner'),
'std' => true,
),
'show_share' => array(
'type' => 'checkbox',
'label' => __('Show Share', 'blogcorner'),
'std' => true,
),
'date_format' => array(
'type' => 'select',
'label' => __('Date Format', 'blogcorner'),
'options' => array(
'format_1' => __('Format 1', 'blogcorner'),
'format_2' => __('Format 2', 'blogcorner'),
),
'std' => 'format_2',
),
'bg_color_option' => array(
'type' => 'color',
'label' => __('Background Color', 'blogcorner'),
'std' => '#c8ccc7',
),
'text_color_option' => array(
'type' => 'color',
'label' => __('Text Color', 'blogcorner'),
'std' => '#000',
),
);
parent::__construct();
}
/**
* Query the posts and return them.
* @param array $args
* @param array $instance
* @return WP_Query
*/
public function get_posts($args, $instance)
{
$query_args = array(
'posts_per_page' => 3,
'post_status' => 'publish',
'no_found_rows' => 1,
'ignore_sticky_posts' => 1
);
if (!empty($instance['category']) && -1 != $instance['category'] && 0 != $instance['category']) {
$query_args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $instance['category'],
);
}
return new WP_Query(apply_filters('Blogcorner_Advanced_Recent_Widget_query_args', $query_args));
}
/**
* Output widget.
*
* @param array $args
* @param array $instance
* @see WP_Widget
*
*/
public function widget($args, $instance)
{
ob_start();
if (($posts = $this->get_posts($args, $instance)) && $posts->have_posts()) {
if (is_active_widget(false, false, $this->id_base, true)) {
$dynamic_css = 'background-color: '.$instance['bg_color_option'].'; color: '.$instance['text_color_option'].';'; // Replace with your dynamic styles
$args['before_widget'] = preg_replace('/class="/', 'style="'. $dynamic_css . '" class="', $args['before_widget'], 1);
}
do_action('blogcorner_before_advanced_recent_widget');
echo $args['before_widget'];
$site_fallback_image = blogcorner_get_option('site_fallback_image');
?>