Copy <?php
class home_xn extends WP_Widget {
function __construct() {
parent::__construct('home_xn', 'Xem nhiều', array('description' => ''));
}
function widget($args, $instance) {
extract($args);
$html = "";
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$sp = apply_filters('widget_text', $instance['sp'], $instance);
$html .= '<div class="sidebar-title title_sec"><a href="#"><?php echo ($title); ?></a></div>';
$html .= '<div class="widget-content">';
$new = new WP_Query('showposts=5&meta_key=post_views_count&orderby=meta_value_num&order=DESC');
while ($new->have_posts()): $new->the_post();
$html .= '<div class="single-post">';
$html .= '<div class="row">';
$html .= '<div class="col-md-4">';
$html .= '<div class="img">';
$html .= '<a href="<?php the_permalink();?>">'.the_post_thumbnail().'</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '<div class="col-md-8">';
$html .= '<h3 class="title"><a href="<?php the_permalink();?>"><?php the_title();?></a></h3>';
$html .= '<small class="text-muted"><i class="fa fa-clock-o"></i> <?php the_time('d/m/Y')?></small>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
endwhile;
$html .= '</div>';
echo $html;
}
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['sp'] = $new_instance['sp'];
return $instance;
}
function form($instance) {
$instance = wp_parse_args((array) $instance, array('title' => '', 'sp' => ''));
$title = strip_tags($instance['title']);
$sp = ($instance['sp']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">
<?php _e('Tiêu đề :');?> </label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title ?>" />
</p>
<?php
}
}
?>