File: /home/rasad/domains/rasadeardakan.ir/private_html/wp-content/themes/ofogh/widget/cat-slider.php
<?php
class post_slider extends WP_Widget {
public function __construct(){
$widget_ops = array(
'classname' => 'post_slider',
'description' => 'آخرین نوشته ها با دسته بندی',
);
parent::__construct( 'post_slider', 'ofogh - اسلایدر ', $widget_ops );
}
function widget( $args, $instance ) {
$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'] );
$author = apply_filters( 'author', $instance['author'] );
$date = apply_filters( 'date', $instance['date'] );
$views = apply_filters( 'views', $instance['views'] );
$comments = apply_filters( 'comments', $instance['comments'] );
?>
<ul class="<?php if($thumb == "on") : ?>full widget_slider<?php else : ?>widget_slider<?php endif; ?> owl-carousel-1">
<?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 class="item">
<div class="thumb">
<?php if(has_post_thumbnail()){?>
<a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url('big'); ?>" alt="<?php the_title(); ?>"></a>
<?php }else{ ?>
<img src="<?php bloginfo("template_url"); ?>/img/none.png">
<?php } ?>
</div>
<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>
<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>
</div>
</li>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
</ul>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-1');
owl.owlCarousel({
rtl: true,
nav: true,
margin:5,
loop: true,
autoplay:true,
autoplayTimeout:5000,
responsive: {
0: {
items: 1
}
}
})
})
</script>
<?php
}
function update( $new_instance, $old_instance ) {
$instance = array();
$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['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[ '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[ '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( '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>
<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( '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_slider_widget() {
register_widget( 'post_slider' );
}
add_action( 'widgets_init', 'post_slider_widget' );
?>