File: /home/rasad/domains/rasadeardakan.ir/private_html/wp-content/themes/ofogh/widget/cat-img-b.php
<?php
class post_img_big extends WP_Widget {
public function __construct(){
$widget_ops = array(
'classname' => 'post_img_big',
'description' => 'آخرین نوشته ها با دسته بندی',
);
parent::__construct( 'post_img_big', 'ofogh - تیتر+عکس بزرگ ', $widget_ops );
}
function widget( $args, $instance ) {
$widget_title = apply_filters( 'widget_title', $instance['widget_title'] );
$post_num = apply_filters( 'post_num', $instance['post_num'] );
$post_cat = apply_filters( 'post_cat', $instance['post_cat'] );
$thumb = apply_filters( 'thumb', $instance['thumb'] );
$rott = apply_filters( 'rott', $instance['rott'] );
$lead = apply_filters( 'lead', $instance['lead'] );
$author = apply_filters( 'author', $instance['author'] );
$date = apply_filters( 'date', $instance['date'] );
$views = apply_filters( 'views', $instance['views'] );
$comments = apply_filters( 'comments', $instance['comments'] );
echo $args['before_widget'];
if( !empty($widget_title) ) {
echo $args['before_title'];
echo $widget_title;
echo $args['after_title'];
}
?>
<ul class="widget_img_big">
<?php
$catquery = new WP_Query('cat=' . $post_cat . '&posts_per_page=' . $post_num .'');
if( $catquery->have_posts() ) :
while( $catquery->have_posts() ) : $catquery->the_post();
?>
<li>
<?php if($thumb == "on") : ?>
<div class="thumb">
<?php if(has_post_thumbnail()){?>
<a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url('medium'); ?>" alt="<?php the_title(); ?>"></a>
<?php }else{ ?>
<img src="<?php bloginfo("template_url"); ?>/img/none.png">
<?php } ?>
</div>
<?php endif; ?>
<div class="det">
<?php if($rott == "on") : ?>
<?php if(get_post_meta( get_the_ID(), 'meta-text-1', true )!=null){ ?><div class="rott"><?php echo get_post_meta( get_the_ID(), 'meta-text-1', true ); ?></div><?php } ?>
<?php endif; ?>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php if($lead == "on") : ?>
<div class="lead">
<?php if(get_post_meta( get_the_ID(), 'lead', true )!=null){ ?>
<?php echo get_post_meta( get_the_ID(), 'lead', true ); ?>
<?php } else { ?>
<?php the_excerpt(); ?>
<?php } ?>
</div>
<?php endif; ?>
</div>
<div class="daat">
<?php if($author == "on") : ?><span><i class="fa fa-user" aria-hidden="true"></i> <?php the_author_posts_link(); ?></span><?php endif; ?>
<?php if($date == "on") : ?><span><i class="fa fa-clock" aria-hidden="true"></i> <?php the_time(' d F Y '); ?></span><?php endif; ?>
<?php if($views == "on") : ?><span><i class="fa fa-signal" aria-hidden="true"></i> <?php echo getPostViews(get_the_ID()); ?></span><?php endif; ?>
<?php if($comments == "on") : ?><span><i class="fa fa-comments" aria-hidden="true"></i> <?php comments_popup_link('0', '1 دیدگاه', '% دیدگاه'); ?></span><?php endif; ?>
</div>
</li>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
<?php
echo $args['after_widget'];
}
function update( $new_instance, $old_instance ) {
$instance = array();
$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : '';
$instance['post_num'] = ( ! empty( $new_instance['post_num'] ) ) ? strip_tags( $new_instance['post_num'] ) : '';
$instance['post_cat'] = ( ! empty( $new_instance['post_cat'] ) ) ? strip_tags( $new_instance['post_cat'] ) : '';
$instance['thumb'] = ( ! empty( $new_instance['thumb'] ) ) ? $new_instance['thumb'] : '';
$instance['rott'] = ( ! empty( $new_instance['rott'] ) ) ? $new_instance['rott'] : '';
$instance['lead'] = ( ! empty( $new_instance['lead'] ) ) ? $new_instance['lead'] : '';
$instance['author'] = ( ! empty( $new_instance['author'] ) ) ? $new_instance['author'] : '';
$instance['date'] = ( ! empty( $new_instance['date'] ) ) ? $new_instance['date'] : '';
$instance['views'] = ( ! empty( $new_instance['views'] ) ) ? $new_instance['views'] : '';
$instance['comments'] = ( ! empty( $new_instance['comments'] ) ) ? $new_instance['comments'] : '';
return $instance;
}
function form( $instance ) {
if ( isset( $instance[ 'widget_title' ] ) ) {
$widget_title = $instance[ 'widget_title' ];
} else {
$widget_title = 'آخرین نوشته ها';
}
if ( isset( $instance[ 'post_num' ] ) ) {
$post_num = $instance[ 'post_num' ];
} else {
$post_num = '3';
}
if ( isset( $instance[ 'post_cat' ] ) ) {
$post_cat = $instance[ 'post_cat' ];
} else {
$post_cat = 'post_cat';
}
if ( isset( $instance[ 'thumb' ] ) ) {
$thumb = $instance[ 'thumb' ];
} else {
$thumb = 'thumb';
}
if ( isset( $instance[ 'rott' ] ) ) {
$rott = $instance[ 'rott' ];
} else {
$rott = 'rott';
}
if ( isset( $instance[ 'lead' ] ) ) {
$lead = $instance[ 'lead' ];
} else {
$lead = 'lead';
}
if ( isset( $instance[ 'author' ] ) ) {
$author = $instance[ 'author' ];
} else {
$author = 'author';
}
if ( isset( $instance[ 'date' ] ) ) {
$date = $instance[ 'date' ];
} else {
$date = 'date';
}
if ( isset( $instance[ 'views' ] ) ) {
$views = $instance[ 'views' ];
} else {
$views = 'views';
}
if ( isset( $instance[ 'comments' ] ) ) {
$comments = $instance[ 'comments' ];
} else {
$comments = 'comments';
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'widget_title' ); ?>">عنوان</label>
<input name="<?php echo $this->get_field_name( 'widget_title' ); ?>" type="text" value="<?php echo esc_attr( $widget_title ); ?>" id="<?php echo $this->get_field_id( 'widget_title' ); ?>" class="widefat">
</p>
<p>
<label for="<?php echo $this->get_field_id( 'post_cat' ); ?>">دسته بندی</label>
<select name="<?php echo $this->get_field_name( 'post_cat' ); ?>" id="<?php echo $this->get_field_id( 'post_cat' ); ?>" class="widefat">
<option value='0'>انتخاب دسته بندی</option>
<?php foreach(get_categories( array('hide_empty' => 0) ) as $cat) { ?>
<option value="<?php echo $cat->cat_ID; ?>"><?php echo $cat->cat_name; ?></option>
<?php } ?>
</select>
</p>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id( 'post_num' ); ?>">تعداد نوشته</label>
<input style="width:100%;" name="<?php echo $this->get_field_name( 'post_num' ); ?>" type="number" step="1" min="1" value="<?php echo esc_attr( $post_num ); ?>" size="3" id="<?php echo $this->get_field_id( 'post_num' ); ?>" class="tiny-text">
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'thumb' ); ?>" id="<?php echo $this->get_field_id( 'thumb' ); ?>" class="checkbox" <?php checked( $thumb, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'thumb' ); ?>">عکس</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'rott' ); ?>" id="<?php echo $this->get_field_id( 'rott' ); ?>" class="checkbox" <?php checked( $rott, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'rott' ); ?>">روتیتر</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'lead' ); ?>" id="<?php echo $this->get_field_id( 'lead' ); ?>" class="checkbox" <?php checked( $lead, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'lead' ); ?>">خلاصه نوشته</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'author' ); ?>" id="<?php echo $this->get_field_id( 'author' ); ?>" class="checkbox" <?php checked( $author, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'author' ); ?>">ارسال کننده</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'date' ); ?>" id="<?php echo $this->get_field_id( 'date' ); ?>" class="checkbox" <?php checked( $date, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'date' ); ?>">تاریخ ارسال</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'views' ); ?>" id="<?php echo $this->get_field_id( 'views' ); ?>" class="checkbox" <?php checked( $views, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'views' ); ?>">تعداد بازدید</label>
</p>
<p>
<input type="checkbox" name="<?php echo $this->get_field_name( 'comments' ); ?>" id="<?php echo $this->get_field_id( 'comments' ); ?>" class="checkbox" <?php checked( $comments, "on" ); ?>>
<label for="<?php echo $this->get_field_id( 'comments' ); ?>">تعداد دیدگاه</label>
</p>
<?php
}
}
function post_img_big_widget() {
register_widget( 'post_img_big' );
}
add_action( 'widgets_init', 'post_img_big_widget' );
?>