File: /home/rasad/public_html/wp-content/themes/ofogh/widget/cat-gallery.php
<?php
class theme_wg_news_gallery_post extends WP_Widget {
function __construct() {
parent::__construct( false, 'ofogh - عکس ها' );
}
function widget( $args, $instance ) {
extract($args, EXTR_SKIP);
echo $before_widget;
echo $before_title;
//Display title as stored in this instance of the widget
echo esc_html($instance['news_title']);
echo $after_title;
print_theme_wg_news_gallery_post($instance);
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['news_title'] = $new_instance['news_title'];
$instance['select_news'] = $new_instance['select_news'];
$instance['news_cat'] = $new_instance['news_cat'];
$instance['news_count'] = $new_instance['news_count'];
return $instance;
}
function form( $instance ) {
$defaults = array(
'news_title' => 'عکس ها',
'news_count' => '6',
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id('news_title'); ?>">عنوان</label>
<input style="width:100%;" type="text" id="<?php echo $this->get_field_id( 'news_title' ); ?>" name="<?php echo $this->get_field_name( 'news_title' ); ?>" value="<?php echo $instance['news_title']; ?>" />
</p>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id('select_news'); ?>">نوع نمايش </label>
<select style="width:100%;" class="select-type" id="<?php echo $this->get_field_id('select_news'); ?>" name="<?php echo $this->get_field_name('select_news'); ?>" type="text">
<option value="1">آخرین</option>
<option value="2">تصادفی</option>
</select>
</p>
<p>
<label style="width:100%;" for="<?php echo $this->get_field_id('news_count'); ?>">تعداد نوشته</label>
<input style="width:100%;" type="number" step="1" min="1" id="<?php echo $this->get_field_id( 'news_count' ); ?>" name="<?php echo $this->get_field_name( 'news_count' ); ?>" value="<?php echo $instance['news_count']; ?>" />
</p>
<?php
echo '<script>';
echo 'document.getElementById("'. $this->get_field_id( 'select_news' ) .'").value = "' . $instance['select_news'] . '";';
echo 'document.getElementById("'. $this->get_field_id( 'news_title' ) .'").value = "' . $instance['news_title'] . '";';
echo 'document.getElementById("'. $this->get_field_id( 'news_count' ) .'").value = "' . $instance['news_count'] . '";';
echo '
jQuery(function($) {
$("#'. $this->get_field_id('select_news'). '").change(function(){
if($("#'. $this->get_field_id('select_news'). '").val() == "3") {
$(".select-cat").show();
} else {
$(".select-cat").hide();
}
});
});
</script>';
}
}
function theme_wg_news_gallery_post_register() {
register_widget( 'theme_wg_news_gallery_post' );
}
add_action( 'widgets_init', 'theme_wg_news_gallery_post_register' );
function print_theme_wg_news_gallery_post($options) { ?>
<ul class="widget_img_small">
<?php
if($options['select_news']==1){
$big_query = new WP_Query(array(
'post_status' =>'publish',
'post_type' => array('gallery'),
'posts_per_page' => $options['news_count']));
} elseif ($options['select_news']==2) {
$big_query = new WP_Query(array(
'post_status' =>'publish',
'post_type' => array('gallery'),
'orderby' => 'rand',
'posts_per_page' => $options['news_count']));
}
if($big_query->have_posts()) : while($big_query->have_posts()) : $big_query->the_post();
?>
<li>
<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 } ?>
<a class="iicon" href="<?php the_permalink(); ?>"><i class="fa fa-camera"></i></a>
</div>
<div class="det">
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<?php if(get_post_meta( get_the_ID(), 'number-photo', true )!=null){ ?>
<div class="ttime"><?php echo get_post_meta( get_the_ID(), 'number-photo', true ); ?></div>
<?php } ?>
</div>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
</ul>
<?php
}
?>