'latest-posts-widget',
'description' => __('List latest posts of your site with thumbnails', 'bizstrait'),
);
parent::__construct('latest-posts-widget', __('Bizstrait Latest Posts', 'bizstrait'), $widget_ops);
}
// Displays latest posts widget on blog.
function widget($args, $instance)
{
global $post;
extract($args);
// $sizes = get_option( 'mkrdip_latest_posts_thumb_sizes' );
$valid_sort_orders = array('date', 'title', 'comment_count', 'rand');
if (in_array($instance['sort_by'], $valid_sort_orders)) {
$sort_by = $instance['sort_by'];
$sort_order = (bool) isset($instance['asc_sort_order']) ? 'ASC' : 'DESC';
} else {
// by default, display latest first
$sort_by = 'date';
$sort_order = 'DESC';
}
// Get array of post info.
$cat_posts = new WP_Query(
array(
'posts_per_page' => $instance['num'],
'orderby' => $sort_by,
'order' => $sort_order,
)
);
echo wp_kses_post($before_widget);
// Widget title
if (!empty($instance['title'])) {
echo wp_kses_post($before_title);
echo wp_kses_post($instance['title']);
echo wp_kses_post($after_title);
}
// Post list
echo "
\n";
while ($cat_posts->have_posts()) {
$cat_posts->the_post();
?>
-
'mr-3',
'style' => 'margin:auto;',
)
);
?>
(int) 20) {
$post_trimmed = substr($theContntStripTags, 0, strpos($theContntStripTags, ' ', (int) 20));
$t_text = $post_trimmed . '...';
echo '
'. esc_html($t_text). '
';
}else{
echo '
'. esc_html($theContntStripTags). '
';
}
?>
";
echo wp_kses_post($after_widget);
// remove_filter( 'excerpt_length', $new_excerpt_length );
wp_reset_postdata();
}
/**
* The widget configuration form back end.
*
* @param array $instance
* @return void
*/
function form($instance)
{
$instance = wp_parse_args(
(array) $instance,
array(
'title' => __('Latest Posts', 'bizstrait'),
'num' => '',
'sort_by' => '',
'asc_sort_order' => '',
'excerpt' => '',
'excerpt_length' => '',
'comment_num' => '',
'date' => '',
'thumb' =>'',
'thumb_w' => '',
'thumb_h' => '',
)
);
$title = $instance['title'];
$num = $instance['num'];
$sort_by = $instance['sort_by'];
$asc_sort_order = $instance['asc_sort_order'];
$excerpt = $instance['excerpt'];
$excerpt_length = $instance['excerpt_length'];
$comment_num = $instance['comment_num'];
$date = $instance['date'];
$thumb = $instance['thumb'];
$thumb_w = $instance['thumb_w'];
$thumb_h = $instance['thumb_h'];
?>