<?php
// 最新文章
// http://www.yinchn.com /
class new_cat extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'new_cat',
'description' => __( '最新文章' ),
'customize_selective_refresh' => true,
);
parent::__construct('new_cat', '主题 最新文章', $widget_ops);
}
function widget( $args, $instance ) {
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', $instance['title'] );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<div class="new_cat">
<ul>
<?php $q = 'showposts='.$instance['numposts']; if (!empty($instance['cat'])) $q .= '&cat='.$instance['cat']; query_posts($q); while (have_posts()) : the_post(); ?>
<li>
<span class="thumbnail">
<?php if (zm_get_option('lazy_s')) { zm_thumbnail_h(); } else { zm_thumbnail(); } ?>
</span>
<span class="new-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></span>
<span class="date"><?php the_time('m/d') ?></span>
<?php if( function_exists( 'the_views' ) ) { the_views( true, '<span class="views"><i class="fa fa-eye"></i> ','</span>' ); } ?>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
</div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['numposts'] = $new_instance['numposts'];
$instance['cat'] = $new_instance['cat'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '最新文章',
'numposts' => 5,
'cat' => 0)); ?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">标题:</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 $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('numposts'); ?>">显示篇数:</label>
<input id="<?php echo $this->get_field_id('numposts'); ?>" name="<?php echo $this->get_field_name('numposts'); ?>" type="text" value="<?php echo $instance['numposts']; ?>" size="3" />
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">选择分类:
<?php wp_dropdown_categories(array('name' => $this->get_field_name('cat'), 'show_option_all' => 全部分类, 'hide_empty'=>0, 'hierarchical'=>1, 'selected'=>$instance['cat'])); ?></label>
</p>
<?php }
}
add_action( 'widgets_init', create_function( '', 'register_widget( "new_cat" );' ) );
// 分类最新文章
class post_cat extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'post_cat',
'description' => __( '以列表形式调用一个分类的最新文章' ),
'customize_selective_refresh' => true,
);
parent::__construct('post_cat', '主题 分类文章', $widget_ops);
}
function widget( $args, $instance ) {
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', $instance['title'] );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<div class="post_cat">
<ul>
<?php $q = 'showposts='.$instance['numposts']; if (!empty($instance['cat'])) $q .= '&cat='.$instance['cat']; query_posts($q); while (have_posts()) : the_post(); ?>
<?php the_title( sprintf( '<li class="cat-title"><i class="fa fa-angle-right"></i><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></li>' ); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul>
<div class="clear"></div>
</div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['numposts'] = $new_instance['numposts'];
$instance['cat'] = $new_instance['cat'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '分类文章',
'numposts' => 5,
'cat' => 0)); ?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">标题:</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 $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('numposts'); ?>">显示篇数:</label>
<input id="<?php echo $this->get_field_id('numposts'); ?>" name="<?php echo $this->get_field_name('numposts'); ?>" type="text" value="<?php echo $instance['numposts']; ?>" size="3" />
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">选择分类:
<?php wp_dropdown_categories(array('name' => $this->get_field_name('cat'), 'show_option_all' => 全部分类, 'hide_empty'=>0, 'hierarchical'=>1, 'selected'=>$instance['cat'])); ?></label>
</p>
<?php }
}
add_action( 'widgets_init', create_function( '', 'register_widget( "post_cat" );' ) );
// 分类文章(图片)
class img_cat extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'img_cat',
'description' => __( '以图片形式调用一个分类的文章' ),
'customize_selective_refresh' => true,
);
parent::__construct('img_cat', '主题 分类图片', $widget_ops);
}
function widget( $args, $instance ) {
extract($args, EXTR_SKIP);
$title = apply_filters('widget_title', $instance['title'] );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<div class="picture img_cat">
<?php $q = 'showposts='.$instance['numposts']; if (!empty($instance['cat'])) $q .= '&cat='.$instance['cat']; query_posts($q); while (have_posts()) : the_post(); ?>
<span class="img-box">
<span class="img-x2">
<span class="insets">
<span class="img-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo wp_trim_words( get_the_title(), 26 ); ?></a></span>
<?php if (zm_get_option('lazy_s')) { zm_thumbnail_h(); } else { zm_thumbnail(); } ?>
</span>
</span>
</span>
<?php endwhile;?>
<?php wp_reset_query(); ?>
<div class="clear"></div>
</div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['numposts'] = $new_instance['numposts'];
$instance['cat'] = $new_instance['cat'];
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array(
'title' => '分类图片',
'numposts' => 4,
'cat' => 0)); ?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">标题:</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 $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('numposts'); ?>">显示篇数:</label>
<input id="<?php echo $this->get_field_id('numposts'); ?>" name="<?php echo $this->get_field_name('numposts'); ?>" type="text" value="<?php echo $instance['numposts']; ?>" size="3" />
</p>
<p>
<label for="<?php echo $this->get_field_id('cat'); ?>">选择分类:
<?php wp_dropdown_categories(array('name' => $this->get_field_name('cat'), 'show_option_all' => 全部分类, 'hide_empty'=>0, 'hierarchical'=>1, 'selected'=>$instance['cat'])); ?></label>
</p>
<?php }
}
add_action( 'widgets_init', create_function( '', 'register_widget( "img_cat" );' ) );
// 近期留言
class recent_comments extends WP_Widget {
public function __construct() {
$widget_ops = array(
'classname' => 'recent_comments',
'desc